How to Find Biggest Files and Directories in Linux
Find largest folder at current working directory command:
du -hs * | sort -rh | head -5
Explain:
- du command: Estimate file space usage.
- -h : Print sizes in human-readable format (e.g., 10MB).
- -S : Do not include the size of subdirectories.
- -s : Display only a total for each argument.
- sort command : sort lines of text files.
- -r : Reverse the result of comparisons.
- -h : Compare human readable numbers (e.g., 2K, 1G).
- head : Output the first part of files.
Alternative command is find.
To find the largest files in a particular location, just include the path beside the find command:
find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
# OR
find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5
The above command will display the largest file from /home/tecmint/Downloads directory.
Source: tecmint.com
Phản hồi gần đây