How to find smallest and largest directories and files in linux
How to find smallest and largest directories and files in linux.
Commands to know:
there is no single command to find the largest directories and files. However, we can use some combination of commands to achieve this task.
1. du -a | sort -n -r | head -n 10
du -ah | sort -n -r | head -n 10 - human readable format.
it shows files in ascending order
Where,
- du : Disk usage command that estimates file space usage
- -a : Displays all directories and files
- sort : Sort lines of text files
- -n : Compare according to string numerical value
- -r : Reverse the result of comparisons
- head : Output the first part of files
- -n 10 : Print the first 10
to show file sizes in ascending order in /var/log in human readable format
3. Let us find out the largest files in the current working directory and its sub-directories:
find -printf '%s%p \n' | sort -nr | head -10
Also, you can skip the directories and display only the files by adding “-type f” flag in the above command:
4. find -type f -printf '%s%p \n' | sort -nr | head -10
to know about usage of find command go to below link
usage-of-find-command.html
5. 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:
find /var -printf '%s%p \n' | sort -nr | head -10
6. Find smallest directories and files in linux
4. find -type f -printf '%s%p \n' | sort -nr | head -10
to know about usage of find command go to below link
usage-of-find-command.html
5. 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:
find /var -printf '%s%p \n' | sort -nr | head -10
6. Find smallest directories and files in linux
du -S . | sort -n | head -10
du -S . | sort -nr | head -10
du -S /var | sort -n | head -10
7. To view the top ten smallest files only in the current working directory, run:
ls -lSr | head -10
ls /var -lSr | head -10
Comments
Post a Comment