How to search Top Files and Directories in Linux
Top Files and Directories in Linux
Top files and directory can be found using the combination of du command which estimates file space usage, sort command to Sort lines of text files or given input data, head command to display the largest file and search file using find command.
Options
du : Estimate file space usage.
a : Displays all files and folders.
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 : Print the first ‘ n’ lines.
-h : Print sizes in human readable format
-s : Display only a total for each argument.
-S : Do not include size of sub directories.
To find top directories current working directories
The following command helps to find top directories in current working directories
Example
[root@linuxhelp Desktop]# du -a | sort -n -r | head -n 3
555440 .
449620 ./CentOS 64
448580 ./CentOS 64/CentOS 64.vmdk
To find largest files in home directory
The following command helps to find largest files in home directory
Example
[root@linuxhelp Desktop]# du -a /home/ | sort -n -r | head -n 5
21916 /home/
21820 /home/user1
14316 /home/user1/.mozilla
14300 /home/user1/.mozilla/firefox
14292 /home/user1/.mozilla/firefox/ow95swzb.default
For more info about du command: https://www.linuxhelp.com/disk-management-linux-du-command/
To display the file size
To display the file size in human readable format, that is in KB, MB, GB
Example
[root@linuxhelp Desktop]# du -hs * | sort -rh | head -n 4
440M CentOS 64
104M Videos
8.0K NEWPASSWD
4.0K NEW~
For more info about head and tail command: https://www.linuxhelp.com/head-tail-command/
To list the large files & directories
To list the large files, directories including sub directories in the current working directories.
Example
[root@linuxhelp Desktop]# du -Sh | sort -rh | head -n 5
440M ./CentOS 64
39M ./Videos/cat cmd
29M ./Videos/grep command final
27M ./Videos/chmod new
8.6M ./Videos/chmod
To find only the largest file size
The following command helps to find only the largest file size and not directories in current working directory.
Example
[root@linuxhelp ~]# find -type f -exec du -Sh {} + | sort -rh | head -n 5
439M ./Desktop/CentOS 64/CentOS 64.vmdk
86M ./.mozilla/firefox/kn1e65t9.default/urlclassifier3.sqlite
39M ./Desktop/Videos/cat cmd/cat cmd.mp4
29M ./Desktop/Videos/grep command final/grep command final.mp4
27M ./Desktop/Videos/chmod new/chmod new.mp4
To find only the biggest file size in specific location
The following command helps to find biggest file size in specific location.
Example
[root@linuxhelp ~]# find /root/ -type f -exec du -Sh {} + | sort -rh | head -n 5
439M /root/Desktop/CentOS 64/CentOS 64.vmdk
86M /root/.mozilla/firefox/kn1e65t9.default/urlclassifier3.sqlite
39M /root/Desktop/Videos/cat cmd/cat cmd.mp4
29M /root/Desktop/Videos/grep command final/grep command final.mp4
27M /root/Desktop/Videos/chmod new/chmod new.mp4
For more info about sort command: https://www.linuxhelp.com/sort-command-linux-examples/
Comments ( 0 )
No comments available