Monday, January 30, 2017

How to Find Out Top Directories and Files (Disk Space) in Linux

1. Run the following command to find out top biggest directories under /home partition.  

# du -a /home | sort -n -r | head -n 5

2. If you want to display the biggest directories in the current working directory, run 

# du -a | sort -n -r | head -n 5

3. 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. 

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

4. To display the largest folders/files including the sub-directories, run: 

# du -Sh | sort -rh | head -5

5. To find the largest 10 files (linux/bash) 

find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

6. To find the largest 10 directories: 

find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

Only difference is -type {d:f}

d = directory
f = files

No comments :

Post a Comment