User Tools

Site Tools


bash_oneliners

BASH oneliners

  • Remove offending key from known_hosts file with one command
$ sed -i 18d .ssh/known_hosts
  • Whats my WAN IP?
$ dig +short myip.opendns.com @resolver1.opendns.com
  • Find large files, print 10 largest files in dir
$ find . -printf '%s %p\n'|sort -nr|head
  • To find the largest file in all sub-directories:
$ find /path/to/folder -type f -exec ls -s {} \; | sort -nr | awk 'NR==1 { $1=""; sub(/^ /, ""); print }'
  • grep for valid IP Addresses.
$ grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" file.txt
  • show used inode count for subdirectories.
find */ | sed 's!/.*!!' | uniq -c
  • free all caches
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
bash_oneliners.txt · Last modified: 2018/04/23 14:31 by admin