User Tools

Site Tools


bash_oneliners

BASH oneliners

  • 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
  • size of all files older than mtime
find . -mtime +7 -print0 | du -hc --files0-from - | tail -n 1
  • To find the largest file in all sub-directories:
find . -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: 2020/06/10 17:27 by admin