打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

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

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)


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
php连接mysql时报错:SQLSTATE[HY000] [2002] No such file or directory
每天学点Linux命令之umask
解压,打包Android的imgags
Linux删除乱码文件或者目录
Linux学习21-设置定时任务crontab
mv命令
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服