SNHPS
Quick and easy code snippets
disk-usage-breakdown.txt

Display the size of each folder and file in the current directory.

#Disk usage
df -h

#Size breakdown of all folders in current directory
sudo du -sh * | sort -rh
find-file-contents.txt

Find all instances of the specified string anywhere in the current folder or its subfolders.

#Case sensitive search
grep -Hrn "foobar"

#Case insensitive search
grep -Hrni "fooBAR"

#Pretty formatting
grep -Hrni "foobar" * --color=always | awk -F: '{print "\n"NR ": " $0}' | awk '{$1=$1};1'

#Limit to 500 characters
grep -Hrni "foobar" * --color=always | awk -F: '{print "\n"NR ": " $0}' | awk '{$1=$1};1' | cut -b 1-400
find-file-or-folder.txt

Locate any files or folders that fully or partially match the given filename.

sudo find . -name "wp-content"
sudo find . -iname "Class-WP-Customize-Section.PHP"
check-public-ip-address.txt

Display the public IP address of the current server.

#Display the IP address of the current device
ip a | grep eth0 | cut -d " " --fields=6 | sed '2q;d' | awk -F'/' '{print $1}'

#Other methods
dig @resolver4.opendns.com myip.opendns.com +short
(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

This website is owned and operated by SiteBolts. All the code snippets found here are intended to be a starting point and should not be treated as a perfect solution to every problem. We do not guarantee the performance, reliability, or security of the code found on this website. As always, you should ensure that you have adequate backups before adding, changing, or executing any code.