shell数据流重定向和管道命令(2)

[root@localhost110 ~]# ls
ab anaconda-ks.cfg a.php b.php composer.phar install.log install.log.syslog log mysql_listen.sh 公共的 模板 视频 图片 文档 下载 音乐 桌面

[root@localhost110 ~]# ls|sort
ab
anaconda-ks.cfg
a.php
b.php
composer.phar
install.log
install.log.syslog
log
mysql_listen.sh
[root@localhost110 ~]# ls|sort -r
mysql_listen.sh
log
install.log.syslog
install.log
composer.phar
b.php
a.php
anaconda-ks.cfg
ab
[root@localhost110 ~]# ls|sort
ab
anaconda-ks.cfg
a.php
A.php
b.php
B.php
composer.phar
D.php
install.log
install.log.syslog
log
mysql_listen.sh
默认不区分大小写

按照文件大小写来排序
[root@localhost110 ~]# ls -l|sort -t ' ' -k 5 -n
总用量 1740
-rw-r--r--. 1 root root 6 10月 16 02:17 1
-rw-r--r--. 1 root root 6 10月 16 02:17 B.php
-rw-r--r--. 1 root root 8 10月 16 01:59 a.php
-rw-r--r--. 1 root root 11 10月 16 02:06 A.php
-rw-r--r--. 1 root root 42 10月 16 01:42 log
-rw-r--r--. 1 root root 140 10月 16 02:02 ab
-rw-r--r--. 1 root root 143 10月 16 01:59 b.php
-rwxrwxrwx. 1 root root 272 1月 27 2016 mysql_listen.sh
-rw-r--r--. 1 root root 1112 10月 16 02:17 D.php
-rw-------. 1 root root 1416 1月 13 2016 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 1月 13 2016 公共的
drwxr-xr-x. 2 root root 4096 1月 13 2016 模板
drwxr-xr-x. 2 root root 4096 1月 13 2016 视频
drwxr-xr-x. 2 root root 4096 1月 13 2016 图片
drwxr-xr-x. 2 root root 4096 1月 13 2016 文档
drwxr-xr-x. 2 root root 4096 1月 13 2016 下载
drwxr-xr-x. 2 root root 4096 1月 13 2016 音乐
drwxr-xr-x. 2 root root 4096 1月 13 2016 桌面
-rw-r--r--. 1 root root 10033 1月 13 2016 install.log.syslog
-rw-r--r--. 1 root root 46328 1月 13 2016 install.log
-rwxr-xr-x. 1 root root 1640731 6月 7 09:40 composer.phar
设置显示方式
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'
[root@localhost110 ~]# ls -l|sort -k 6
总用量 1740
-rw-r--r--. 1 root root 10033 2016-01-13 17:42:57 install.log.syslog
-rw-r--r--. 1 root root 46328 2016-01-13 17:48:20 install.log
-rw-------. 1 root root 1416 2016-01-13 17:48:28 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 公共的
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 模板
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 视频
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 图片
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 文档
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 下载
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 音乐
drwxr-xr-x. 2 root root 4096 2016-01-13 17:52:58 桌面
-rwxrwxrwx. 1 root root 272 2016-01-27 05:54:08 mysql_listen.sh
-rwxr-xr-x. 1 root root 1640731 2016-06-07 09:40:58 composer.phar
-rw-r--r--. 1 root root 42 2016-10-16 01:42:05 log
-rw-r--r--. 1 root root 8 2016-10-16 01:59:03 a.php
-rw-r--r--. 1 root root 143 2016-10-16 01:59:45 b.php
-rw-r--r--. 1 root root 140 2016-10-16 02:02:19 ab
-rw-r--r--. 1 root root 11 2016-10-16 02:06:07 A.php
-rw-r--r--. 1 root root 6 2016-10-16 02:17:17 1
-rw-r--r--. 1 root root 6 2016-10-16 02:17:21 B.php
-rw-r--r--. 1 root root 1112 2016-10-16 02:17:30 D.php
wc指令
wc [-lwm] filename 统计功能
-l 统计行
-w 统计词
-m 统计字符
[root@localhost110 ~]# wc -l log
8 log
[root@localhost110 ~]# cat log|wc -l
8
[root@localhost110 ~]# cat log|wc -w
10
[root@localhost110 ~]# cat log -n
1 php
2 ajax
3 java
4 python
5 nginx mysql
6 GO p erlang
7 PHP5
8
[root@localhost110 ~]# cat log|wc -m
53
[root@localhost110 ~]# cat log1|wc -m
12
[root@localhost110 ~]# cat log1 -n
1 p h p
2 1 2 3

结尾算一个字符

还有 cut/join/paste等

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d3c05341e0798abe546c290daca477b1.html