Show files by size in ls command
In Category Command Line
The “ls -lS” command can be used to get the list of files sorted by their size with biggest size first.
[neo@techpulp ~]# ls -lS total 60 -rw-rw-r-- 1 neo neo 10381 2008-12-06 00:53 ifconfig.pdf drwxr-xr-x 3 neo neo 4096 2008-12-05 02:35 Desktop drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Documents drwxr-xr-x 2 neo neo 4096 2008-12-05 00:59 Download drwxrwxr-x 3 neo neo 4096 2008-12-05 01:46 Examples drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Music drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Pictures drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Public drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Templates drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Videos drwxrwxr-x 3 neo neo 4096 2008-12-05 20:06 workspace -rw-rw-r-- 1 neo neo 122 2008-12-06 01:39 monitor.sh -rw-rw-r-- 1 neo neo 44 2008-12-06 01:33 1.sh [neo@techpulp ~]#
The “ls -lSr” command can be used to get the list of files sorted by their size with smallest size first.
[neo@techpulp ~]# ls -lSr total 60 -rw-rw-r-- 1 neo neo 44 2008-12-06 01:33 1.sh -rw-rw-r-- 1 neo neo 122 2008-12-06 01:39 monitor.sh drwxrwxr-x 3 neo neo 4096 2008-12-05 20:06 workspace drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Videos drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Templates drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Public drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Pictures drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Music drwxrwxr-x 3 neo neo 4096 2008-12-05 01:46 Examples drwxr-xr-x 2 neo neo 4096 2008-12-05 00:59 Download drwxr-xr-x 2 neo neo 4096 2008-12-04 22:11 Documents drwxr-xr-x 3 neo neo 4096 2008-12-05 02:35 Desktop -rw-rw-r-- 1 neo neo 10381 2008-12-06 00:53 ifconfig.pdf [neo@techpulp ~]#
If you want to get plain list of file names, just avoid “-l” option in the above command. You can use output of this command to populate a shell variable in a script or variable in GNU Makefile.
[neo@techpulp ~]# ls -S ifconfig.pdf Desktop Documents Download Examples Music Pictures Public Templates Videos workspace monitor.sh 1.sh [neo@techpulp ~]# ls -Sr 1.sh monitor.sh workspace Videos Templates Public Pictures Music Examples Download Documents Desktop ifconfig.pdf [neo@techpulp ~]#
This is my first time comment at your blog.
Good recommended website