ubuntu:directory:find_largest_and_smallest_directories
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ubuntu:directory:find_largest_and_smallest_directories [2020/02/25 22:16] – created peter | ubuntu:directory:find_largest_and_smallest_directories [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Ubuntu - Directory - Find largest and smallest directories ====== | ====== Ubuntu - Directory - Find largest and smallest directories ====== | ||
+ | |||
+ | ===== Find Largest Directories And Files ===== | ||
To find out the top largest ten directories and files in the current working directory, just run: | To find out the top largest ten directories and files in the current working directory, just run: | ||
Line 31: | Line 33: | ||
sudo du /var -a | sort -n -r | head -n 10 | sudo du /var -a | sort -n -r | head -n 10 | ||
</ | </ | ||
+ | |||
+ | To display the above results in human-readable format, add “-h” parameter: | ||
+ | |||
+ | <code bash> | ||
+ | sudo du -ah /var | sort -n -r | head -n 10 | ||
+ | </ | ||
+ | |||
+ | Let us find out the largest files in the current working directory and its sub-directories: | ||
+ | |||
+ | <code bash> | ||
+ | sudo find -printf '%s %p\n'| sort -nr | head -10 | ||
+ | </ | ||
+ | |||
+ | You can skip the directories and display only the files by adding “-type f” flag in the above command: | ||
+ | |||
+ | <code bash> | ||
+ | sudo find -type f -printf '%s %p\n'| sort -nr | head -10 | ||
+ | </ | ||
+ | |||
+ | To find out the largest files in a specific directory (Ex. /var) and its sub-directories just mention the path of the directory as shown below: | ||
+ | |||
+ | <code bash> | ||
+ | sudo find /var -printf '%s %p\n'| sort -nr | head -10 | ||
+ | </ | ||
+ | |||
+ | You have now basic idea about how to find the largest files and directories. | ||
+ | |||
+ | |||
+ | <code bash> | ||
+ | du -a -h –max-depth=1 | sort -hr | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Find Smallest Directories And Files ===== | ||
+ | |||
+ | To view the top ten smallest directories in the current working directory, run: | ||
+ | |||
+ | <code bash> | ||
+ | du -S . | sort -n | head -10 | ||
+ | </ | ||
+ | |||
+ | To view the smallest directories in a specific location, for example /var, run: | ||
+ | |||
+ | <code bash> | ||
+ | sudo du -S /var | sort -n | head -10 | ||
+ | </ | ||
+ | |||
+ | To view the top ten smallest files only in the current working directory, run: | ||
+ | |||
+ | <code bash> | ||
+ | ls -lSr | head -10 | ||
+ | </ | ||
+ | |||
+ | Likewise, to view the top ten smallest files only in a specific directory, for example /var, just run: | ||
+ | |||
+ | <code bash> | ||
+ | sudo ls -lSr /var | head -10 | ||
+ | </ | ||
+ | |||
ubuntu/directory/find_largest_and_smallest_directories.1582669015.txt.gz · Last modified: 2020/07/15 09:30 (external edit)