You must often encounter the problem of insufficient disk space in linux system as a linux admin, At this time, what do you for this problem? I think you need to check of which the biggest files or directories occupied on your disk, so you can decide if some files can be removed or moved to others disk or partication to get space. so now the problem is how to find largest files or directories in linux or a directory.
this article will guide you how to use Linux find command to find larget files or directories in a directory under linux operating system.
Find The Largest Files In Current Directory
To find the largest files in a given directory or in the current directory, you can use “ls” command with “-S” option to list all the largest files , the option “-S” will sort files in descending order by their size. issue the following command:
1 2 3
| ls -lS .
or
ls -ls /path |
output:
1 2 3 4 5
| [root@itsprite ~]# ls -lS
total 3808
-rw------- 1 root root 3885425 May 18 03:21 nohup.out
drwxr-xr-x 3 root root 4096 Aug 18 2013 cn
-rw-rw-r--+ 1 root root 14 May 6 17:30 test1 |
Find The Larget Directories In Current Directory
To find the largest directories in current directory or given directory, you need to use “du” command with “-S” option and sort command with “-nr” option, issue the following commad:
you can give a target directory to list all largest directries in it, type:
output:
1 2 3 4 5 6 7 8 9 10 11 12
| [root@itsprite ~]# du -S /home | sort -nr
20 /home/user1
16 /home/user2
16 /home/mysql
4 /home
[root@itsprite ~]# du -S . | sort -nr
3872 .
8 ./.ssh
8 ./cn/test/scr
4 ./cn/test
4 ./cn |
Find The Largest Files In A Directory recursively
To find the largest file in a directory and its subdirectories , you should use find command and combine with sort command , issue the following command to find all files and show up the first 10 largest files in current directory:
1
| find . -type f | sort -nr | head -n 10 |
output:
1 2 3 4 5 6 7 8 9 10 11
| [root@itsprite var]# find . -type f | sort -nr | head -n 10
./spool/plymouth/boot.log
./spool/mail/www
./spool/mail/user2
./spool/mail/user1
./spool/mail/mysql
./spool/anacron/cron.weekly
./spool/anacron/cron.monthly
./spool/anacron/cron.daily
./run/utmp
./run/syslogd.pid |
See Also:
1. Linux Find Command Examples
2. Linux find command
3. Linux find command manual page
done…..
|