How to sort files by size in Linux
Linux how to sort files by size, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Use sort to sort
[root@vps ~] # ll | grep'^ [^ d]'| sort-n
-rw- 1 root root 0 Aug 4 19:21 ipp.txt
-rw- 1 root root 232 Aug 4 19:23 openvpn-status.log
-rw-r--r-- 1 root root 2095419 Jul 27 14:57 nagios-plugins-1.4.15.tar.gz
-rw-r--r-- 1 root root 3215350 Mar 9 11:49 nagios-3.2.1.tar.gz
-rw-r--r-- 1 root root 626042 Apr 30 2008 lzo-2.03.tar.gz
-rw-r--r-- 1 root root 669076 Mar 17 2009 openvpn-2.0.9.tar.gz
-rw-r--r-- 1 root root 6697 Aug 2 00:39 1.tar.gz
Total 6500
[root@vps ~] # ll-h | grep'^ [^ d]'| sort-n
-rw- 1 root root 0 Aug 4 19:21 ipp.txt
-rw- 1 root root 232 Aug 4 19:23 openvpn-status.log
-rw-r--r-- 1 root root 2.0M Jul 27 14:57 nagios-plugins-1.4.15.tar.gz
-rw-r--r-- 1 root root 3.1m Mar 9 11:49 nagios-3.2.1.tar.gz
-rw-r--r-- 1 root root 612K Apr 30 2008 lzo-2.03.tar.gz
-rw-r--r-- 1 root root 654K Mar 17 2009 openvpn-2.0.9.tar.gz
-rw-r--r-- 1 root root 6.6K Aug 2 00:39 1.tar.gz
Total 6.4M
Summary: using sort to sort numbers is a big mistake!
For example:
[root@vps ~] # cat .txt
one
two
ten
nineteen
[root@vps ~] # sort .txt
one
ten
nineteen
two
[root@vps ~] #
Sort will only rank the first character!
Second, directly use the ls parameter
[root@vps ~] # ll-S | grep'^ [^ d]'
Total 10000
-rw-r--r-- 1 root root 3565833 Aug 5 10:07 httpd-2.2.16.tar.gz.filepart
-rw-r--r-- 1 root root 3215350 Mar 9 11:49 nagios-3.2.1.tar.gz
-rw-r--r-- 1 root root 2095419 Jul 27 14:57 nagios-plugins-1.4.15.tar.gz
-rw-r--r-- 1 root root 669076 Mar 17 2009 openvpn-2.0.9.tar.gz
-rw-r--r-- 1 root root 626042 Apr 30 2008 lzo-2.03.tar.gz
[root@vps ~] # ll-Sh
[root@vps] # ll-Srh-these two are the most commonly used
3. Sort by time
[root@vps ~] # ll-rt
Total 6500
-rw-r--r-- 1 root root 626042 Apr 30 2008 lzo-2.03.tar.gz
-rw-r--r-- 1 root root 669076 Mar 17 2009 openvpn-2.0.9.tar.gz
-rw-r--r-- 1 root root 3215350 Mar 9 11:49 nagios-3.2.1.tar.gz
-rw-r--r-- 1 root root 2095419 Jul 27 14:57 nagios-plugins-1.4.15.tar.gz
Drwxrwxrwx 13 1000 users 4096 Aug 1 02:30 lzo-2.03
Drwxrwxrwx 16 root root 4096 Aug 2 00:28 openvpn-2.0.9
-rw-r--r-- 1 root root 6697 Aug 2 00:39 1.tar.gz
Drwxrwxrwx 16 nagios root 4096 Aug 3 20:26 nagios-plugins-1.4.15
Drwxrwxr-x 15 nagios nagios 4096 Aug 3 21:08 nagios-3.2.1
-rw- 1 root root 0 Aug 4 19:21 ipp.txt
-rw- 1 root root 232 Aug 4 19:26 openvpn-status.log
[root@vps ~] #
Note: usage of ls in solaris: ls-1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [file], no-S option
Sort by file size
Ls-l | sort-n + 4-5
After reading the above, have you mastered the method of sorting files by size in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!