Unix commands

Find Largest Directories in Linux

If you want to display the biggest directories in the current working directory, Some of you would like to display the above result in human readable format. i.e you might want to display the largest files in KB, MB, or GB. 1

du -hs * | sort -rh | head -5

What is running on this port?

Using netstat Command

netstat (network statistics) command is used to display information concerning network connections, routing tables, interface stats and beyond.2

netstat -ltnp | grep -w ':80'

Using lsof Command

lsof command (LiSt Open Files) is used to list all open files on a Linux system2

lsof -i :80

Find a file

To find all files in current directory3:

# find . -name "*.yaml"

and to delete all of those files 5:

# find . -name "*.yaml" -delete

Find a directory

To find all directory from the current location 6

# find . -type d -name "folder"

and to delete this folders 7:

# find . -type d -name "foo" -exec rm -rf {} +
# find . -type d -name "bar" -exec rm -rf "{}" \;

Find a file that contains a string

find files from here that contain "text-to-find"4

# find . -type f -exec grep -H 'text-to-find' {} \;
  1. UNIX Find A File Command, on September 28, 2017

Last updated