系统环境
[root@db01 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@db01 ~]# uname -r
3.10.0-862.el7.x86_64
第一个命令—pgrep
根据命令名称,我们不难猜到,这是一个关于grep的命令。以p作为前缀,那就是过滤匹配出进程方面的命令。
用该命令过滤出关于redis的进程号
[root@db01 ~]# pgrep redis
73394
当然,也可以用指定的分隔符将数字合在一行并隔开,以逗号,
为例,加上-d
参数
[root@db01 ~]# pgrep mysql -d ","
1605,1774,4371,4379,18991,127300
也可以显示的更全面一些,加上-l
参数,显示进程号和名称
[root@db01 ~]# pgrep ssh -l
1230 sshd
6630 sshd
126808 sshd
第二个命令—split
该命令可以将很大的文件平均分割成指定大小的文件,剩余补齐,源文件不会被改动
首先生成一个1000M的文件
[root@db01 ~]# dd if=/dev/zero of=/root/big_data bs=100M count=10
10+0 records in
10+0 records out
1048576000 bytes (1.0 GB) copied, 4.77132 s, 220 MB/s
然后每个150M的大小平均分割
[root@db01 ~]# split -b 150M big_data
[root@db01 ~]# ll
total 2048000
-rw-r--r-- 1 root root 1048576000 Aug 6 16:32 big_data
-rw-r--r-- 1 root root 157286400 Aug 6 16:44 xaa
-rw-r--r-- 1 root root 157286400 Aug 6 16:44 xab
-rw-r--r-- 1 root root 157286400 Aug 6 16:44 xac
-rw-r--r-- 1 root root 157286400 Aug 6 16:44 xad
-rw-r--r-- 1 root root 157286400 Aug 6 16:44 xae
-rw-r--r-- 1 root root 157286400 Aug 6 16:44 xaf
-rw-r--r-- 1 root root 104857600 Aug 6 16:44 xag
可以看到,源文件不会变化;新生成6个150M的文件和1个100M的文件
既然可以分割,当然也可以合并
[root@db01 ~]# cat x* > new_data
[root@db01 ~]# ll
-rw-r--r-- 1 root root 1048576000 Aug 6 16:32 big_data
-rw-r--r-- 1 root root 1048576000 Aug 6 16:47 new_data
第三个命令—nl
在Linux中查看文件内容,我们经常用cat
。这个命令比cat
多了一个显示行号的功能,基本相同。
使用方法:nl 文件名