分享

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

 CNTech 2015-01-19

Sometimes, Maybe you have some specific request as a linux admin, it is to find the smallest files or directory in a directory or in the current directory, or you need to know how to find the files  or list all files or directories in a directory and sort by file size. How to find smallest files or directories using Linux find command in linux system. how to list all the smallest files or directories on your linux system.

This guide will show you on how to find  smallest files /directories by size under linux operating system.

Find The Smallest Files In A Directory

Often, if you want to list all files in a directory, you can use “ls” comand with a few options per your specific request. now the below example will show you how to use “ls” command with both “-S” and “-r” options  to list the smallest files in a directory.

where, “-r” options will reverse the sorting order of the listing. “-S” option will do sorting operation. Issue the following command to find the smallest files in the current  directory:

1
ls -lSr

If you just wnat to see the first 10 smallest file, you can use pipe line and follow to “head -n” command.

1
ls -lSr | head -n 10

output:

1
2
3
4
5
6
7
8
9
10
11
[root@itsprite var]# ls -lSr | head -n 10
total 64
lrwxrwxrwx.  1 root root   10 Dec 17  2012 mail -> spool/mail
drwxr-xr-x.  2 root root 4096 Sep 23  2011 yp
drwxrwxrwt.  2 root root 4096 Sep 24 15:38 tmp
drwxr-xr-x.  8 root root 4096 Dec 17  2012 spool
drwxr-xr-x. 10 root root 4096 Jun 27 18:04 run
drwxr-xr-x.  2 root root 4096 Sep 23  2011 preserve
drwxr-xr-x.  2 root root 4096 Sep 23  2011 opt
drwxr-xr-x.  2 root root 4096 Sep 23  2011 nis
drwxr-xr-x.  4 root root 4096 Oct 12 03:27 log

Find The Smallest Directories In A Directory

using “du” command with “-S” options, which will put the size in kilobytes of each directory in the first column of output , you can give the target directory you want to search and pipe the output to sort command with ‘-n’ option, type:

1
du -S . | sort -n | head -n 10

 
Output:

1
2
3
4
5
6
7
8
9
10
11
[root@itsprite var]# du -S .  | sort -n | head -n 10
4       .
4       ./cache
4       ./cache/man/cat1
4       ./cache/man/cat2
4       ./cache/man/cat3
4       ./cache/man/cat4
4       ./cache/man/cat5
4       ./cache/man/cat6
4       ./cache/man/cat7
4       ./cache/man/cat8

 
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)
  2. Linux: Finding files using linux find command (16.6)
  3. Linux commands: How To find files or directories (19)
  4. Linux Commands: Linux Find Command Examples (19.5)
  5. CentOS /Linux: Deep Understand Linux Man Command (23.7)
  6. Linux:How To Find All Files OR Directories Which Belong To A User Or Group (25)
  7. Linux:How To Find Largest Files /Directories In A Directory (37.1)
  8. Linux:How To Setup A Shared Directory (17.5)
  9. Linux: Deleting Directory Using Rmdir Or Rm Command (18)
  10. Linux: Get Directory Name From File’s Absolute Path (14.3)
  11. Linux:How to find all Hidden Files or directories (25.1)
  12. Linux:4 ways to Delete All Files In A Directory But Some Speicial Files (15.2)
  13. Linux/Unix:How to use find command to search files in linux (26)
  14. Linux / Unix: How to Find and delete All Hidden Dot Directories (14)


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

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多