分享

Linux:How To Find Largest Files /Directories In A Directory ? IT Sprite

 CNTech 2015-01-19

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:

1
du -S . | sort -nr

 
you can give a target directory to list all largest directries in it, type:

1
du -S /path | sort -nr

 
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…..

 

Related Articles:

  1. Linux: Finding Out All large files (16.8)
  2. Linux: Finding files using linux find command (17.9)
  3. Linux commands: How To find files or directories (22.9)
  4. Linux Commands: Linux Find Command Examples (20.7)
  5. Linux:How To Find All Files OR Directories Which Belong To A User Or Group (27.1)
  6. Linux:How To Find Smallest Files /Directories In A Directory (37.4)
  7. Linux:How To Setup A Shared Directory (17.9)
  8. Linux: Deleting Directory Using Rmdir Or Rm Command (20.8)
  9. Linux: Get Directory Name From File’s Absolute Path (17)
  10. Linux:How to find all Hidden Files or directories (24.5)
  11. Linux:4 ways to Delete All Files In A Directory But Some Speicial Files (14.4)
  12. Linux/Unix:How to use find command to search files in linux (25.9)
  13. File Archive Or Compression Command (tar,gzip,zip,bzip2) Examples In Linux (15.2)
  14. Linux / Unix: How to Find and delete All Hidden Dot Directories (17.9)


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多