31.文件查看与排序-ls+du+df+sort
文件查看与排序
文件查看
作用:确定文件类型
语法:file 路径/文件名
举例:
[root@bogon Desktop]# file test.sh
test.sh: Python script, ASCII text executable
文件排序
ls –ltr
按时间排序,t表示时间,r表示从小到大,如果不加r表示从大到小
[root@bogon ~]# ls -ltr
total 44
-rw-------. 1 root root 2035 Nov 30 21:16 anaconda-ks.cfg
-rw-r--r--. 1 root root 2128 Nov 30 21:16 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Templates
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Public
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Videos
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Pictures
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Music
drwxr-xr-x. 2 root root 6 Dec 3 12:03 Documents
-rwxr-xr-x 1 root root 33212 Dec 3 15:35 360linuxc(10.92.102.201_8080_8090).sh
drwxr-xr-x. 2 root root 51 Dec 3 16:08 Downloads
drwxr-xr-x. 2 root root 56 Dec 4 22:59 Desktop
ls –lSr
按文件大小排序,S表示时间,r表示从小到大,如果不加r表示从大到小
[root@bogon ~]# ls -lSr
total 44
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Videos
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Templates
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Public
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Pictures
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Music
drwxr-xr-x. 2 root root 6 Dec 3 12:03 Documents
drwxr-xr-x. 2 root root 51 Dec 3 16:08 Downloads
drwxr-xr-x. 2 root root 56 Dec 4 22:59 Desktop
-rw-------. 1 root root 2035 Nov 30 21:16 anaconda-ks.cfg
-rw-r--r--. 1 root root 2128 Nov 30 21:16 initial-setup-ks.cfg
-rwxr-xr-x 1 root root 33212 Dec 3 15:35 360linuxc(10.92.102.201_8080_8090).sh
ls –lSrh
按文件大小排序,S表示时间,r表示从小到大,如果不加r表示从大到小, h表示看大小,更清楚
[root@bogon ~]# ls -lSrh
total 44K
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Videos
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Templates
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Public
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Pictures
drwxr-xr-x. 2 root root 6 Nov 30 21:17 Music
drwxr-xr-x. 2 root root 6 Dec 3 12:03 Documents
drwxr-xr-x. 2 root root 51 Dec 3 16:08 Downloads
drwxr-xr-x. 2 root root 56 Dec 4 22:59 Desktop
-rw-------. 1 root root 2.0K Nov 30 21:16 anaconda-ks.cfg
-rw-r--r--. 1 root root 2.1K Nov 30 21:16 initial-setup-ks.cfg
-rwxr-xr-x 1 root root 33K Dec 3 15:35 360linuxc(10.92.102.201_8080_8090).sh
查看目录和分区
du –sh 目录
查看某个目录大小
[root@bogon ~]# du -sh Desktop/
20K Desktop/
df -h
[root@bogon ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 55G 4.0G 51G 8% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 13M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 497M 166M 332M 34% /boot
tmpfs 781M 8.0K 781M 1% /run/user/42
tmpfs 781M 36K 781M 1% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /mnt
大文件排序
cat 文件名 | sort | more
[root@bogon Desktop]# cat test.sh | sort | more
sort –n 文件名
文件中数值默认从小到大
[root@bogon Desktop]# sort -n test.txt
1
2
5
6
32
34
47
682
695
958
3726
sort –r 文件名
文件中数值默认从大到小
[root@bogon Desktop]# sort -r test.txt
958
695
682
6
5
47
3726
34
32
2
1
sort –M 文件名
按月份排序
[root@bogon Desktop]# sort -M wang.txt
January
February
March
April
组合使用
-t 指定一个用来区分键位置字符
-k 后面跟数字,指定按第几列进行排序
-r 反序排序(升序变成降序进行排序)
sort –t “分割符” –k数值 –r 路径/文件 | more
以“:”为分隔符,将第3列的大小由大到小排列
[root@bogon Desktop]# sort -t ":" -k3 -r /etc/passwd | more
du –h 目录 | sort –r | more
把/etc目录下所有文件,文件大小由大到小排序
[root@bogon Desktop]# du -h /etc/ | sort -r | more

浙公网安备 33010602011771号