Useful bash one-liners.
- http://www.commandlinefu.com/
- https://github.com/stephenturner/oneliners/
- http://genomespot.blogspot.com/2013/08/a-selection-of-useful-bash-one-liners.html
A newline is ignored in a few contexts where there is manifestly an unterminated command. These
contexts include after a control operator (&&
, ||
, |
, &
, ;
, ;;
, but not !
). I don't
see this documented in the bash manual. In POSIX, it's specified via the
grammar rules
. Wherever the rules have linebreak
, you can have zero or more line breaks.
Comments in a multi-line bash command
https://superuser.com/questions/238791/comments-in-a-multi-line-bash-command
Put the pipes at the end of line with the comments after it:
echo 'foo' |
sed 's/f/a/' | # change first f to a
sed 's/o/b/' | # change first o to b
sed 's/o/c/' # change second o to c abc
#abc
Number each line in file.txt:
cat -n file.txt
Count the number of unique lines in file.txt
cat file.txt | sort -u | wc -l
https://apple.stackexchange.com/a/47841
Set the window to 100x30 characters:
printf '\e[8;30;100t'
Move the window to the top/left corner
printf '\e[3;0;0t'
find . -type d -print0 | xargs -0 du -s | sort -n | tail -20 | cut -f2 | xargs -I{} du -sh {}
BIN_NAME=lastz ps ax | grep "${BIN_NAME}" | cuf -f 1 | xargs kill -9