关于shell的几个不为人知却十分有用的命令分享

2019-09-23 09:19:16刘景俊

10. hkg03s16-in-f8.1e100.net          0.0%    41    4.8   4.9   4.7   5.0   0.1

2.nl命令,给所查看的文本加上行号,如下

cat a.log
aa

nl a.log
1 aa
 3.shuf命令,随机从一个文件或者一个文件夹中选取行或者文件

[root@localhost mwq]# ls | shuf -n1
a.log
[root@localhost mwq]# ls | shuf -n1
a.log
[root@localhost mwq]# ls | shuf -n1
a.log
[root@localhost mwq]# ls | shuf -n1
20140512.sql
[root@localhost mwq]# ls | shuf -n1
20140512.sql
[root@localhost mwq]# ls | shuf -n1
a.log
[root@localhost mwq]# vim a.log
[root@localhost mwq]# cat a.log | shuf -n1
aa
[root@localhost mwq]# cat a.log | shuf -n1
dd
[root@localhost mwq]# cat a.log | shuf -n1
aa
[root@localhost mwq]# cat a.log | shuf -n1
ff

 当然你也可以改变参数如cat a.log | shuf -n2获取两行内容。

4.last命令,查看上次登录或者登出的用户


root     pts/4        xxxxxxxxxxx    Sun May 18 19:12   still logged in  
root     pts/4        xxxxxxxxxxx    Fri May 16 09:39 - 15:17  (05:38)   
root     pts/4        xxxxxxxxxxx    Wed May 14 17:13 - 18:01  (00:48)   
root     pts/4        xxxxxxxxxxx    Mon May 12 10:50 - 13:38  (02:47)   
root     pts/4        xxxxxxxxxxx    Mon May 12 10:48 - 10:50  (00:02)   
root     pts/1        xxxxxxxxxxx    Fri May  9 11:58   still logged in

5.pstree以树的结构显示当前的进程节点

init─┬─abrt-dump-oops
 ├─abrtd
 ├─acpid
 ├─atd
 ├─auditd───{auditd}
 ├─avahi-daemon───avahi-daemon
 ├─console-kit-dae───63*[{console-kit-da}]
 ├─crond
 ├─dbus-daemon───{dbus-daemon}
 ├─hald───hald-runner─┬─hald-addon-acpi
 │    └─hald-addon-inpu
 ├─irqbalance
 ├─java───330*[{java}]
 ├─master───qmgr
 ├─6*[mingetty]
 ├─mysqld_safe───mysqld───11*[{mysqld}]
 ├─rhsmcertd───rhsmcertd
 ├─rsyslogd───3*[{rsyslogd}]