[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Click for more| Home]

Post bash commands you use every day that people might not know about.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 112
Thread images: 6

File: rpibash.png (3KB, 327x130px) Image search: [iqdb] [SauceNao] [Google]
rpibash.png
3KB, 327x130px
Post bash commands you use every day that people might not know about.
>>
Useful aliases are cool too.
>>
mv ~ /dev/null
>>
>>45507245
wtf
how do i undo that
i tried mv /dev/null ~ it didn't work
>>
>>45507294
you just got rekt

I seriously hope you didn't do that.
>>
>>45507294
lol
>>
>>45507294
ebin
>>
>>45507294
You deleted your home folder, you dumb fuck!
>>
>>45507324
>>45507342
>>45507349
He's obviously kidding you idiots
>>
>implying you have privileges to delete your home folder
>>
>>45507370
What? Of course your do. They're owned by the user and group of the users they represent and are 700 by default.
>>
>>45507245
Top kek
>>
>>45507420
Yeah, but you need to have permission for the containing folder (/home/ in this case) in order to delete/move/create a file.
>>
File: vqfT5j4.jpg (52KB, 615x934px) Image search: [iqdb] [SauceNao] [Google]
vqfT5j4.jpg
52KB, 615x934px
>>45505636
It's not really a "bash command", but I forced myself to learn loops once and for all (instead of having to look them up every damn time I needed one). Now I can quickly use a loop (either "for FILE in *.ext" or "cat stuff.txt | while read LINE") every time I need to rename a bunch of file or look through a file. I could probably use awk or sed for that, but they're pretty complicated I find.

Add to this "parameter substitutions" (I think they're called that) and you never have to do anything manually ever again.

Plus if you're using zsh you can write your commands multi-line which make them less error-prone.
>>
>>45507509
tested only on zsh:
alias pls='sudo ${${(z)$(fc -l -1)}[@]:1:20}'

"pls" instead of "sudo !!"
>>
anyone has the script for downloading all images from 4chan thread?
>>
>>45507466
No you don't.
>>
>>45507597
wget -m 4chan.org
>>
>>45507576
Wouldn't it be much easier to just do

alias pls='sudo $(fc -ln -1)'

or am I missing something here? oO

That would also work in bash, of course
>>
^X ^E opens your current line in $EDITOR. Save and close it and it will be run.
>>
>>45507656
Why not simply alias pls='sudo [email protected]' ?
>>
>>45507669
Damn, that's pretty fucking useful...
>>
Bash? My history says
chsh -s /bin/zsh
>>
>>45507509
I've been doing this too, because of virsh's fucking stupid limitations.

e.g., want to destroy all VMs? Surely I could run virsh destroy --all... Nope!

Have to type out all of:

for i in vm1 vm2 vm3 vm4; do
virsh destroy $i
done

It's fucking stupid. Need to get around to aliasing it.
>>
File: C-x_C-e.png (2KB, 235x45px) Image search: [iqdb] [SauceNao] [Google]
C-x_C-e.png
2KB, 235x45px
>>45507669
holy shit, that's amazing
>>
>>45507466
That is not how *nix works.
>>
>>45507669
Oh shit nigger...
>>
>>45507720
>>45507701
>>45507669
except I never fucking needed it
>>
sudo rm -rf /
>>
>>45507725
Well it can be useful for people like me who are constantly fucking up everything when crafting a command with more than 2 pipes or 5 flags for a single command
>>
>>45507747
but usually its about getting command in to the commandline
not from the commandline in to editor
>>
>>45507732
>get a load of this guy

Also more like
sudo rm -rf / && sudo yum -y install gentoo
>>
>>45507754
But you would remove the 'sudo' and 'yum' binaries when you run that command...
>>
>>45507751
Yes it is, usually - of course writing the command in the commandline has the advantage of faster try/correct/enhance iterations. Sometimes I exactly know what a complex command should look like, though - usually when a long regex is included - and just keep failing to enter it correctly into the shell. I guess doing that in Vim could help.
>>
>>45507761
Liar. Installing Gentoo is always an option.
>>
ls . | grep ".txt"

Or for when you are in your /media or /mnt folder and have only one disk mounted and it has that random string of characters but you can't be arsed to type it in or copy it so you do
cd $(ls)
>>
>>45507709
>>45507606
Fucking newbies.
>>
>>45507797
>type first 3 characters
>press tab

hng
>>
Not sure if it works with bash but with zsh:
Ctrl+z to suspend task
do something else
%,Enter
resumes suspended task.

I find it useful for vim and dmesg mainly.
>>
>>45507797
ls *.txt?
>>
>>45507672
Then you also could use alias pls="sudo"
but he wants it to be "sudo !!"
>>
>>45507805
No your fucking retarded.
That guy did not move ~, he moved ~/*.
>>
>>45507817
or simply ^Z to suspend task, then bg to run it in the background. Or fg to resume it.

You can even have multiple suspended tasks and list them with jobs
>>
>>45507817
Yep, that works in bash as well.
Continuing with
fgRET

is easier for me, though.
>>
>>45507838
Oh thanks, guess I'm not as good as I thought
>>
I took notes while reading a book on the Linux console, here is my resulting cheat sheet:

cd,mv,cp,touch
grep root /etc/passwd //prints lines with root in it
// grep uses regexps, path uses wildcards
//-v for case insensative, -v for inverts to find not matching
*,?, . // wildcards, single quote expands wildcard in command
cat // prints out contents of file, concats two files
rm -rf
source
. // means source (reads file, to make current in shell)
more spc,q,b
less , b-up, spc-down ,G-end, g-begin, /chars-search, n-next search,
h-help, q-quit
diff file file
find dir -name file -print //use '*' quotes on star because shell also expands wkds
head or tail // shows first 10 lines, use -n to alter number of lines
sort //alphabetic sort, -n to sort numbers -r to reverse
passwd //change password
hi=ho, $hi // evals ho, echo $hi // prints ho
//can put less commandline options in LESS env variable
LESS=blah, export stuff //need to export env variable
ctrl shell commands- b-left,f-right,p-up,n-down,a-beginline,e-endline,
w-erase preceding word,u-erase line
man|info, -h|--help, /usr/share/doc
command > file //creates file if it does not exist, can clobber if does exist
>> //appends instead of clobbers file
ps ax,u,axu,w //w wraps long process names, ps u $$ // check process of current sh
kill pid //stops process, kill -STOP pid // freeze but not terminate // -CONT
ctrl-z stops, clrl-c kills, fg or bg starts again //foreground/background
ctrl-d stops input entry, may terminate program
command file & // puts running of command in background so you get shell
ctrl-l // does clear
ln -s // soft link, no -s is hard link
whereis // finds all locations of commands
which // tells which of whereis is used, doesnt work on aliases
type // what kind of command (can I use which?)
; // puts multiple commands on one line
>>
>>45507845
Can you read?

>>45507245
>>
>>45507848
>>45507858
Nice!
I only use zsh and came across this by accident when ^ZZ'ing in vim.
>>
>>45507656
probably yes, I don't remember my thinking when writing that, I was young and naive and bashed it together without understanding (I am still young and naive and still do it)
>>
It's surprising how many people don't know about
screen
^L
^R
/, n to search in man pages

Other things I use almost every day
python -m http.server
sudo !!
init 0
>>
>>45508010
>screen
Deprecated, please use tmux nigga
>>
$fortune -o
A man without a God is like a fish without a bicycle.
>>
Pressing esc followed by any number and a key will enter that key the given number of times. Not sure how useful or unknown this is.
>>
also proven to be quite useful:
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias cd.....='cd ../../../..'

alias df='df -kTh'

alias pingg='ping -c 3 www.google.com'
>>
alias clock="watch -t -n 1 'date +%H:%M:%S | figlet'"

BAM! 1337 clock in your terminal. Impress your friends
>>
>>45508059
alias help='sudo rm -rf /'
>>
>>45508063
If you use tmux there's a clock mode. ^B T if I'm not mistaken.
>>
>>45508059
>alias cd..='cd ..'
I really don't understand why I didn't do this years ago.
>>
>>45508070
>almost 2015
>being 13
>>
>>45508087
im a girl
>>
>>45508092
We're all little girls here, anon.
>>
>>45508092

for you
>>
:(){ :|: & };:
>>
File: g meetup.jpg (489KB, 1280x912px) Image search: [iqdb] [SauceNao] [Google]
g meetup.jpg
489KB, 1280x912px
yt()
{
youtube-dl -o - $1 | mpv -
}


>>45508096
Me, next to glasses
>>
>>45508097
>>45508096
im a 13 year old girl
>>
>>45508109
mpv recently got integrated support for working with youtube-dl

try
mpv --ytdl <url>

with an up to date mpv/youtube-dl
>>
>>45508134
it used to just work with any youtube URL.
good to know.

Do I still have to do horrific workarounds to get DASH video and audio?
>>
>>45508109
does youtube provide anything clive doesn't provide? Call me a pleb but clive x is shorter than youtube-dl x.
>>
>>45508109
Me with the smartphone
>>
>>45508070
>not using --no-preserve-root
>>
Tree
Ack
>>
"pass" is a cool and minimalist password manager which stores your info in gpg-encrypted files. Combine that with a dmenu-script and you have something very nice with no bloat.
>>
>>45508059
Wtf? I have the exact same aliases including the df and pingg one. Motherfucking no way.

I also have

Alias dus='du -hc --summarize .'
>>
>>45507701
How do you do that on vim?
>>
>>45508063

Easy

^T on tmux lol
>>
alias s='sudo -E '

-E preserves your environment, and the additional space does something else I don't remember.
>>
>>45509727
leading spaces stop things from showing up in history.
>>
3MB webms using 2-pass encoding.
dicks(){ # file.mkv starttime endtime [width]
seq 2 | xargs -I {} ffmpeg -y\
-ss $2 -i "$1" -to $3 -an ${4:+-vf scale=$4:-1} -f webm -c:v vp8\
-b:v $((24536678 / $(($(date +%s -d $3) - $(date +%s -d $2)))))\
-quality good -threads 4 -cpu-used 0 -pass {} "${1%.*} [$2 - $3].webm"
rm -f ffmpeg2pass-0.log
}
>>
>>45509145
?
~ export EDITOR=vim
C-x C-e
i
echo werksESC
:wq
~
echo werks
werks
~
>>
alias update='sudo pacman -Syuu'
alias purge='sudo pacman -R'
alias trim='sudo fstrim -v /'
>>
>>45509727
what does sudo -e do? never heard of that. I just make it so i never get asked password
>>
dominatetheworld
>>
--help
>>
>>45507669
10/10
>>
>>45507732
Sudo rm -rf --no-preserve-root /
>>
>>45507669
Learned something new. Thank you.
>>
I used linux for awhile without ever using the search history option

>ctrl + r
Pretty handy
>>
tmux is also really handy for working in ssh
>>
>>45509759
saved
>>
>>45511722
tmux is really handy for everything
>>
I alias
ls - lah
to ll. Simple, but saves me a ton of keystrokes at work.
>>
>bash
>he doesn't use zsh
>>
>>45511790
zsh is so feature rich I'm actually put off by it.
>>
>>45511773
True I can tell I've only scratched the surface of what it can do, anything beyond attaching and detaching from sessions I can never remember though. Even that I'd have to go look up. It's pretty much a necessity for working in ssh or things get all fucked up like I'll forget I'm ssh'd in and suspend my computer or something stupid.
>>
File: 1402602927081.gif (466KB, 500x281px) Image search: [iqdb] [SauceNao] [Google]
1402602927081.gif
466KB, 500x281px
http://lists.research.att.com/pipermail/ast-users/2014q4/004652.html

bash is deprecated
>>
>>45511806
We actually played a session of multiplayer zork once by having a bunch of people ssh into the same box and attach to the same tmux session

One of my friends and I work on the same box and sometimes I'll open another window attached to his session to see what neat stuff he's doing
>>
>>45507466
?

gum:~/ $ echo ~
/home/gum

drwxr-xr-x 106 gum users 8.0K Dec 7 15:01 gum/
>>
File: 1411352927930.jpg (37KB, 301x267px) Image search: [iqdb] [SauceNao] [Google]
1411352927930.jpg
37KB, 301x267px
saving this thread
>>
some aliases and functions:
 alias ls='ls --color=auto -hF --group-directories-first'
alias q='exit'
alias s2us='for file in *;do mv $file ${file// /_};done' #space2underscore

function mkcd ()
{
mkdir -p "[email protected]" && eval cd "\"\$$#\"";
}

function stfu()
{
exec "[email protected]" 1>/dev/null 2>/dev/null &
}
>>
>>45508363
Use aliases, you faggot.
>>
>>45507697
use 'find -name "vm*" -delete'
>>
>>45508010

My lecturer shown me screen whilst I was doing my final year project; it's been so helpful for network troubleshooting.

I've found Midnight Commander to be useful for general file manipulation too.
>>
Remove old git branches:
git branch --merged | grep -e 'master' -e 'dev' -v | xargs -n 1 git branch -d
>>
>>45505660
I always liked

alias simon_says=sudo

I'm not sure if "useful" is a good word for it, though.
>>
alias duf='du -sk * | sort -n | perl -ne '\''($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}'\'
# fucking useful command to get the size of every subdirectory of the current one

alias ls="ls -ltrh"
# orders items by last modification, which is just oh so useful I can't even
>>
>>45512334

ls -lhrt was a Godsend when finding the right log files while I was in the BlackBerry NOC.
>>
>>45512334
lol wut

du -h -d1
>>
>>45512480
kek
>>
This one is VERY basic but it saves me a lot of time:
# Creates a new folder and cd's to it
function take()
{
mkdir $1
cd $1
}

>>
>>45511826
ya but it's universal, so it's nice to be comfy with it. it takes 2 seconds to add a bash profile to some box that you ssh into :3
>>
>>45513237
This should have been there by default.
>>
really simple, but Im surprised I didnt know this:

just entering cd will take you back to your home directory

cd - will take you to the previous directory you were in
Thread posts: 112
Thread images: 6


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]
Please support this website by donating Bitcoins to 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
If a post contains copyrighted or illegal content, please click on that post's [Report] button and fill out a post removal request
All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site. This means that 4Archive shows an archive of their content. If you need information for a Poster - contact them.