Here are some useful Bash snippets and commands for various tasks:
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Read more about Bash History here
Sorted by Memory Usage:
ps aux | sort -nk +4 | tail
or just simple output:
ps aux
With 30 Characters:
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
grep -RnisI '<string>' *
find /path/to/search -name "filename.txt"
Based on size, then MD5 hash:
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate
date '+%Y-%m-%d %H:%M:%S'
rm !(*.foo|*.bar|*.baz)
This command starts in current directory. Change find .
to find /dir/
to change search path.
find . -type d -empty -delete
cp file.txt{,.bak}
mv filename.{old,new}
chmod --reference file1 file2
chgrp --reference file1 file2
chown --reference file1 file2
export VARIABLE_NAME=value
bind -P
For nice output use this cmd:
bind -P | grep -v "is not" | sed -e 's/can be found on/:/' | column -s: -t
If you are using a different shell this will not work. On ZSH you need to do:
bindkey -L
Pretty print will also work but output from bindkey is okay.