Linux Tips and Tricks

Linux Tips and Tricks

Find the large file/directory

October21

The following commands are used to find out the largest file and directory

Find out the largest file in the directory

$ ls -lS | head -5
total 180416
-rw-r–r– 1 kamaraj kamaraj 58911671 2010-07-15 01:55 Shakira_Waka_Waka.mp4
-rwxrwxrwx 1 kamaraj kamaraj 47224409 2010-07-20 02:20 qt-creator-linux-x86-opensource-2.0.0.bin
-rw-r–r– 1 kamaraj kamaraj 20165034 2010-10-08 00:12 skype-ubuntu-intrepid_2.1.0.81-1_i386.deb
-rw-r–r– 1 kamaraj kamaraj 8833362 2009-08-23 23:37 RealPlayer11GOLD.deb

Find out the largest file and its size in KB

$ ls -lS | head -5 | awk ‘{print $5/1024 “KB” , $8}’
0KB
57530.9KB Shakira_Waka_Waka.mp4
46117.6KB qt-creator-linux-x86-opensource-2.0.0.bin
19692.4KB skype-ubuntu-intrepid_2.1.0.81-1_i386.deb
8626.33KB RealPlayer11GOLD.deb

find out the file which has the size between 100k and 150k

$ find /etc -size +100k -size -150k
/etc/X11/xkb/base.xml
/etc/ssh/moduli

Find out the file which has more than 50 MB

$ find . -type f -size +50000k -exec ls -lh {} \; | awk ‘{ print $8 “: ” $5 }’
./Shakira_Waka_Waka.mp4: 57M

Find out the largest Directory

The below command will top 5 directories that occupies more space in MB (if you want in GB then, replace [0-9]M to [0-9]G)

$ du -h | grep [0-9]M | sort -n -r  | head -5
508M    ./Maathi Yosi (2010)
238M    ./jdk1.6.0_10
108M    ./jdk1.6.0_10/jre
107M    ./jdk1.6.0_10/jre/lib
65M    ./Perl-Report

posted under Uncategorized

Email will not be published

Website example

Your Comment:


Recent Comments

    Categories