ls命令

** ls [OPTION]… [FILE]…

常用选项:

-a 可以看到全部文件(包括隐藏文件)
-ll /-l 列举目录内容的细节,包括权限(模式)、所有者、群组、大小、创建创建日期、文件是否是到系统其它地方的链接,以及链接的指向
-d 查看当前文件夹的属性
-F 在每一个列举项目之后添加一个符号。
/ 表明是一个目录
@表明是到其他文件的符号链接
*表明是到其他文件的符号链接
-f 对输出的文件不进行排序,对-aU选项生效,对-lst选项失效
-r 逆向(reverse) 从后向前地列举目录中的内容
-R 递归(recursive) 递归地列举所有目录(在当前目录之下的)
-S 大小(size) 按文件大小排序
-color 对输出着色,当可以是“never”、“auto”或“always”

cd

切换目录

cd ~ 或者cd 进入到用户家目录
cd - 进入上次的目录,并且显示上次目录路径
cd . . 返回上一层目录
cd . 进入当前目录


pwd

查看当前所在目录

-bash功能特性

命令相关

shell程序找到输入命令所对应的可执行文件或代码,并分析后提交给内核分配资源,将其运行起来,表现形式为一个或多个进程
shell中可执行的两类命令:

  • 内建命令:shell自带
  • 外部命令:安装后的,某个文件系统路径下有对应的可执行文件
  • 相关命令:type/whereis/which
  1. [root@tenor ~]# type find
  2. find is /usr/bin/find
  3. [root@tenor ~]# type cd
  4. cd is a shell builtin
  5. [root@tenor ~]# which find
  6. /usr/bin/find
  7. [root@tenor ~]# which ls
  8. alias ls='ls --color=auto'
  9. /usr/bin/ls
  10. [root@tenor ~]# whereis ls
  11. ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
  12. [root@tenor ~]# whereis find
  13. find: /usr/bin/find /usr/share/man/man1/find.1.gz

命令格式:

command [options…][arguments…]

  • options:长短选项

短选项 - 可以缩写
长选项 —

  • arguments:命令作用的对象/命令提供数据

命令执行结果:
成功:0
失败:1~255
echo $?
ps:1.多个选项及参数之间使用空格字符分割,短选项可以合写
2.取消命令执行:ctrl+c

[root@tenor ~]#  cat/etc/sysconfig/network-scripts/ifcfg-ens32 
-bash: cat/etc/sysconfig/network-scripts/ifcfg-ens32: No such file or directory
[root@tenor ~]# echo $?
127

命令历史:

查看历史命令:history
历史命令文件:.bash_history 上一次shell所保留的命令
登录shell时会读取历史命令文件,并将后续的操作命令添加到历史命令文件中

histroy 命令相关参数:
history -a:追加本地会话执行的命令历史列表到历史文件当中
history -d:删除历史中指定的命令
history -c:清空历史命令

[root@tenor ~]# history -d  108(命令历史ID)

快捷操作:
!# :调用历史列表中的第#条命令
!string :调用历史列表中最近一条一String开头的命令
!!:调用上一条命令

路径补全

tab可以进行补全,唯一
double tab 输出所有符合补全条件的选项

别名

查看别名:alias
定义别名:alias [name]=[value] #只对当前会话有效
取消别名:unalias [name]

[root@tenor ~]# alias pingdu='ping www.baidu.com'
[root@tenor ~]# pingdu
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=48 time=8.68 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=48 time=8.59 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=3 ttl=48 time=8.58 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=4 ttl=48 time=8.59 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 8.583/8.616/8.689/0.042 ms
[root@tenor ~]# unalias  pingdu
[root@tenor ~]# pingdu
-bash: pingdu: command not found

对当前用户有效,需要写如~/.bashrc 配置文件中,并让其生效

[root@tenor ~]# vi ~/.bashrc
在里面添加定义的别名 
[root@tenor ~]# source .bashrc      # 立即生效

快捷键

   在命令行下
Ctrl+a 将光标移到行首
Ctrl+e 将光标移动到行尾
Ctrl+f 将光标向前移动一个字符
Ctrl+b 退格
Ctrl+d 从一个shell中登出
Ctrl+l 清屏
Ctrl+m 回车
Ctrl+p 擦除从history缓冲区找回的一行文本
Ctrl+q 恢复终端的stdin
Ctrl+s 解冻终端的stdin
Ctrl+t 交换光标位置的光标的前一个位置的字符内容
eg:echo $var;,假设光标在a上,那么, 按下C-T之后,v和a将会交换位置:echo $avr
Ctrl+\ 退出
Ctrl+ / Ctrl- 撤销操作
Alt+u 将光标所在位置到词尾的所有字母转为大写
Alt+l 将光标所在位置到词尾的所有字母转为小写
Alt+r 取消所有变更,并将当前恢复到历史记录中的原始状态
(前提是当前命令是从历史记录中来的,如果是手动输入,则会清空行)
Alt+t 当光标两侧都存在词的时候,交换光标两侧词的位置

man手册

  • shell 程序搜寻可执行文件的路径定义
echo $PATH
  • 帮助使用:

help
使用man手册
信息页 info
程序自身帮助文档(readme)
程序官方文档
发行版官方文档
Google

目录管理类命令:

mkdir

创建目录
-p:递归创建
-v:显示创建过程
-m:目录的权限

rmdir

删除目录
-p:递归删除
-v:显示删除过程

[root@tenor ~]# cd /tmp
[root@tenor tmp]# pwd
/tmp
[root@tenor tmp]# mkdir -pv book/liunx
mkdir: created directory ‘book’
mkdir: created directory ‘book/liunx’
[root@tenor tmp]# rmdir -pv book/liunx
rmdir: removing directory, ‘book/liunx’
rmdir: removing directory, ‘book’

tree(系统本身没有)

列出目录结构

[root@tenor tmp]# yum install tree -y
[root@tenor tmp]# tree
.
|-- cvm_init.log
|-- net_affinity.log
|-- nv_driver_install.log
|-- nv_gpu_conf.log
|-- setRps.log
|-- systemd-private-a673cf29abaf489c96f09f591ec2f757-ntpd.service-mrusYF
|   `-- tmp
|-- virtio_blk_affinity.log
`-- virtio_blk_affinity_udev.log

2 directories, 7 files

文件常用命令

cat

查看文件内容

tac

查看文件内容(从尾部开始)
从最后一行开始反向查看一个文件的内容

more

查看部分文件内容

less

查看部分文件内容

head

查看部分文件内容(默认查看文件前10行内容)
-c :获取前多少个字符(字节)
-n:获取前多个行(默认前10行)

tail

查看部分内容(默认查看文件后10行数据)
-c:获取后多少个字符(字节)
-n:获取后多少行
-f:跟踪显示文件追加的新内容(默认后10行)与tailf命令相似

tailf

实时追踪文件尾部内容

[root@tenor ~]# tail -c 12  /var/log/messages
 user root.
[root@tenor ~]# tail -c 150  /var/log/messages

Feb  6 16:10:01 VM_0_3_centos systemd: Started Session 1212 of user root.
Feb  6 16:10:01 VM_0_3_centos systemd: Starting Session 1212 of user root.
[root@tenor ~]# tail -n 5  /var/log/messages
Feb  6 16:09:01 VM_0_3_centos systemd: Starting Session 1211 of user root.
Feb  6 16:10:01 VM_0_3_centos systemd: Started Session 1212 of user root.
Feb  6 16:10:01 VM_0_3_centos systemd: Starting Session 1212 of user root.
Feb  6 16:11:01 VM_0_3_centos systemd: Started Session 1213 of user root.
Feb  6 16:11:01 VM_0_3_centos systemd: Starting Session 1213 of user root.
[root@tenor ~]# head -n 5  /var/log/messages

Jan 21 17:32:06 VM_0_3_centos rsyslogd: imjournal: journal reloaded... [v8.24.0 try http://www.rsyslog.com/e/0 ]
Jan 21 17:32:06 VM_0_3_centos systemd-logind: Powering Off...
Jan 21 17:32:06 VM_0_3_centos ntpd[4058]: ntpd exiting on signal 15
Jan 21 17:32:06 VM_0_3_centos systemd-logind: System is powering down.
[root@tenor ~]# head -c 150 /var/log/messages

Jan 21 17:32:06 VM_0_3_centos rsyslogd: imjournal: journal reloaded... [v8.24.0 try http://www.rsyslog.com/e/0 ]
Jan 21 17:32:06 VM_0_3_centos system[root@tenor ~]#

文件时间戳

Access: 2019-08-05 15:05:41.572796981 +0800 访问时间(读取文件内容)atime
Modify: 2019-08-05 15:05:41.572796981 +0800 修改时间(改变文件内容)mtime
Change: 2019-08-05 15:05:41.572796981 +0800 改变时间(metadata改变)ctime

touch 命令

-a : 只更改atime
-m: 只更改mtime
-t: 指定更改时间

[root@tenor ~]# touch hello                 #创建文件
[root@tenor ~]# stat hello                  #查看文件的元数据信息
  File: ‘hello’
  Size: 0             Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d    Inode: 393356      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-02-06 15:36:50.124353125 +0800
Modify: 2020-02-06 15:36:50.124353125 +0800
Change: 2020-02-06 15:36:50.124353125 +0800
 Birth: -
[root@tenor ~]# echo "linux" > hello
[root@tenor ~]# stat hello
  File: ‘hello’
  Size: 6             Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 393356      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-02-06 15:36:50.124353125 +0800
Modify: 2020-02-06 15:39:26.640915590 +0800
Change: 2020-02-06 15:39:26.640915590 +0800
 Birth: -
[root@tenor ~]# vi hello
 [root@tenor ~]# touch -a -t
touch: option requires an argument -- 't'
Try 'touch --help' for more information.
[root@tenor ~]# touch hello  -a -t
touch: option requires an argument -- 't'
Try 'touch --help' for more information.
[root@tenor ~]# touch hello  -a -t 202002061537    # 更改到分钟,时间不加空格冒号 
[root@tenor ~]# stat hello
  File: ‘hello’
  Size: 21            Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 393379      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-02-06 15:37:00.000000000 +0800
Modify: 2020-02-06 15:42:00.513500045 +0800
Change: 2020-02-06 15:43:01.689334750 +0800
 Birth: -

文件管理类命令

cp

复制文件

[root@localhost ~]# cp --help
Usage: cp [OPTION]... [-T] SOURCE DEST

常用参数:
-r/-R:递归复制目录和文件
-i:交互式
-a:归档,文件相关属性
-p:连同文件属性一起复制
注意项:
1.SRC(原文件)为单个文件:
DEST(目的文件)不存在,将SRC文件内容写入DEST文件中
DEST存在,将SRC文件覆盖DEST文件中
如果DEST为目录,创建新文件并写入内容
2.SRC为多个文件:
DEST必须为目录
3.SRC为目录:需要使用-r参数
DEST为目录:
DEST不存在:创建同名目录和一致性文件
DEST存在:一致性文件
DEST为文件:报错

mv

移动文件
常用参数:
-i:交互式
-f:强制性

rm

删除文件
常用参数:
-i:交互式
-r:递归
-f:强制删除
rm -rf cb :可以实现对目录cb的删除操作

文件链接

方式:

  • 软链接:类似windows快捷方式
  • 硬链接:为inode分配多个文件,通过文件名找到inode,从而读取文件信息

inode :一个指向数据存储位置的指针
image.png

[root@tenor ~]# stat 1.txt
  File: ‘1.txt’
  Size: 73            Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d    Inode: 393356      Links: 1
权限                          用户ID                   组ID           
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-02-06 16:35:19.464257061 +0800
Modify: 2020-02-06 16:36:12.373129284 +0800
Change: 2020-02-06 16:36:12.373129284 +0800
 Birth: -
Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
  or:  ln [OPTION]... TARGET                  (2nd form)
  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)
  or:  ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

ln

设置文件链接
常用参数:
-s:建立软连接(默认情况为硬链接)
-f:强调

[root@tenor ~]# ln 1.txt hard.txt
[root@tenor ~]# ls -i
527194 1-2.txt  527141 book      393379 hello
393356 1.txt    393356 hard.txt  527164 test
[root@tenor ~]# ln 1.txt soft.txt -s
[root@tenor ~]# ls -i
527194 1-2.txt  527141 book      393379 hello     527164 test
393356 1.txt    393356 hard.txt  393373 soft.txt

ps:
1.当我们创建硬链接文件的时候,inode不会发生改变,链接数会加1,同时文件内容相同
2.当我们创建软链接文件的时候,inode会重新分配,链接数保持1,同时文件内容相同
3.链接的目的:在节省存储空间的情况下,共享文件
4.当源文件内容发生改变,软硬链接文件内容都会改变
5.删除源文件之后,硬链接存在,软连接失效, 硬链接的源文件可以说是表现上是独立的

[root@tenor ~]# rm 1.txt
rm: remove regular file ‘1.txt’? y
[root@tenor ~]# cat hard.txt
kkkkkkk
[root@tenor ~]# cat soft.txt
cat: soft.txt: No such file or directory

硬链接的特点:

  • 不论是修改源文件(test 文件),还是修改硬链接文件(test-hard 文件),另一个文件中的数据都会发生改变。
  • 不论是删除源文件,还是删除硬链接文件,只要还有一个文件存在,这个文件都可以被访问。
  • 硬链接不会建立新的 inode 信息,也不会更改 inode 的总数。
  • 硬链接不能跨文件系统(分区)建立,因为在不同的文件系统中,inode 号是重新计算的
  • 硬链接不能连接目录

软链接的特点:

  • 不论是修改源文件(check),还是修改软链接文件(check-soft),另一个文件中的数据都会发生改变。
  • 删除软链接文件,源文件不受影响。而删除原文件,软链接文件将找不到实际的数据,从而显示文件不存在。
  • 软链接会新建自己的 inode 信息和 block,只是在 block 中不存储实际文件数据,而存储的是源文件的文件 名及 inode 号。
  • 软链接可以链接目录。
  • 软链接可以跨分区

       <br />       **   删除文件名的时候,会将它的link数减1,当link数为0的时候,占用的空间将释放掉**
    

    重定向

  • 程序=指令+数据

    数据(输入和输出)
    每打开一个文件都会有一个文件描述符fd


  • 输入输出

    - 标准输入
    - 标准输出 1
    - 标准错误输出 2
    

输出重定向

  - >:覆盖重定向 1
  - >>:追加重定向 1
  - 2>: 覆盖重定向标准错误输出流
  - 2>>:追加重定向标准错输出流
标准输出流
[root@tenor ~]# echo "hello mj" >1.txt
[root@tenor ~]# cat 1.txt
hello mj
[root@tenor ~]# echo "hello lars" >>1.txt
[root@tenor ~]# cat 1.txt
hello mj
hello lars
错误输出流
[root@tenor ~]# lnd  2> 2.txt
[root@tenor ~]# cat 2.txt
-bash: lnd: command not found
[root@tenor ~]# hjkdhflsh  2>> 2.txt
[root@tenor ~]# cat 2.txt
-bash: lnd: command not found
-bash: hjkdhflsh: command not found
标准输出和错误输出到各自不同的位置
[root@tenor ~]# ll 1> 1.txt 2> 2.txt
[root@tenor ~]# cat 1.txt          #2.txt文件位空,结果为空值会覆盖之前的内容
total 8
--wxrwx--x+ 2 lars mxh     0 Feb 11 21:44 1.txt
-rw-rw-r-x  1 root root    0 Feb 11 21:44 2.txt
-rw-r--r--  1 root root    0 Feb  9 22:49 3.txt
--wxrwx--x+ 2 lars mxh     0 Feb 11 21:44 hard.txt
drwxr-xr-x  2 root root 4096 Feb  8 18:41 home
drwxrwxr-x+ 2 root root 4096 Feb 11 00:36 mxh
[root@tenor ~]# mmmm  1> 1.txt 2> 2.txt
[root@tenor ~]# cat 2.txt
-bash: mmmm: command not found
command 1>/path/to/someoutfile 2>/path/to/someoutfile
日志
/dev/null:垃圾桶
  • 合并标准输出和错误输出为同一数据流进行重定向
    • &>:覆盖重定向1+2
    • &>>:追加重定向 1+2
    • 1>&2:将标准输出流重定向到错误输出流(>>)
    • 2>&1: 将错误输出流重定向到标准输出流(>>)
[root@tenor ~]#  lld &> 1.txt
[root@tenor ~]# cat 1.txt
-bash: lld: command not found
[root@tenor ~]# ll &>> 1.txt
[root@tenor ~]# cat 1.txt
-bash: lld: command not found
total 20
--wxrwx--x+ 2 lars mxh    30 Feb 11 21:48 1.txt
-rw-rw-r-x  1 root root   31 Feb 11 21:45 2.txt
-rw-r--r--  1 root root    0 Feb  9 22:49 3.txt
--wxrwx--x+ 2 lars mxh    30 Feb 11 21:48 hard.txt
drwxr-xr-x  2 root root 4096 Feb  8 18:41 home
drwxrwxr-x+ 2 root root 4096 Feb 11 00:36 mxh
[root@tenor ~]# lld 1> 1.txt 2> 2.txt 2>&1      #1.txt 标准输出  2.txt 错误输出
[root@tenor ~]# cat 1.txt
-bash: lld: command not found
[root@tenor ~]# cat 2.txt
[root@tenor ~]# ll 1> 1.txt 2> 2.txt 1>&2
[root@tenor ~]# cat 1.txt
[root@tenor ~]# cat 2.txt
total 8
--wxrwx--x+ 2 lars mxh     0 Feb 11 21:55 1.txt
-rw-rw-r-x  1 root root    0 Feb 11 21:55 2.txt
-rw-r--r--  1 root root    0 Feb  9 22:49 3.txt
--wxrwx--x+ 2 lars mxh     0 Feb 11 21:55 hard.txt
drwxr-xr-x  2 root root 4096 Feb  8 18:41 home
drwxrwxr-x+ 2 root root 4096 Feb 11 00:36 mxh

标准输入

  • 覆盖:

cat > /path/filename <<EOF

  • 追加:

cat >> /path/filename << EOF

[root@tenor ~]# cat > 1.txt
ssss<^H  <<EOF



^C
[root@tenor ~]# 
[root@tenor ~]# cat 1.txt
ssss  <<EOF



[root@tenor ~]# cat >>  1.txt
mahhhhh <<EOF
^C
[root@tenor ~]# cat 1.txt
ssss  <<EOF



mahhhhh <<EOF

管道

  • command 1| command 2 | command 3|.……

ps:最后一个命令会在当前shell进程的子进程中执行,前一个命令的执行结果会由当前命令继续使用

  • 由左向右依次

tr 转换

-d:删除

[root@tenor ~]# tr --h
Usage: tr [OPTION]... SET1 [SET2]
案例1:将/etc/passed 中的前5行  将小写转换为大写,追加到/tmp/passwd.output
[root@tenor ~]# head -n 5 /etc/passwd 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@tenor ~]# head -n 5 /etc/passwd |tr 'a-z' 'A-Z'
ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN
DAEMON:X:2:2:DAEMON:/SBIN:/SBIN/NOLOGIN
ADM:X:3:4:ADM:/VAR/ADM:/SBIN/NOLOGIN
LP:X:4:7:LP:/VAR/SPOOL/LPD:/SBIN/NOLOGIN
[root@tenor ~]# head -n 5 /etc/passwd |tr 'a-z' 'A-Z' > /tmp/passwd.output
[root@tenor ~]# cat /tmp/passwd.output
ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN
DAEMON:X:2:2:DAEMON:/SBIN:/SBIN/NOLOGIN
ADM:X:3:4:ADM:/VAR/ADM:/SBIN/NOLOGIN
LP:X:4:7:LP:/VAR/SPOOL/LPD:/SBIN/NOLOGIN

案例2 将登陆至当前系统上用户信息中的最后1行的信息转换为大写后保存至1.txt中  
[root@tenor ~]# who | tail -n 1 | tr 'a-z' 'A-Z' >1.txt
[root@tenor ~]# cat 1.txt
ROOT     PTS/3        2020-02-11 21:38 (117.136.90.19)

案例3.将文件中的:删除之后重定向到新文件中                      
[root@tenor ~]# cat 2.txt
mhfdlahfaljh:
hdslfhlj: jalhfla
halfhalhf:>>EOF
[root@tenor ~]# cat 2.txt | tr -d ":" > 1.txt
[root@tenor ~]# cat 1.txt
mhfdlahfaljh
hdslfhlj jalhfla
halfhalhf>>EOF

wc 统计

-l:统计行数
-w:统计单词数
-c:统计字符数

[root@tenor ~]# wc --help
Usage: wc [OPTION]... [FILE]...
  or:  wc [OPTION]... --files0-from=F
 [root@tenor ~]# cat mj.txt
-bash: lll: command not found
colos
[root@tenor ~]# wc -l mj.txt
2 mj.txt
 [root@tenor ~]# wc -w mj.txt
6 mj.txt
[root@tenor ~]# wc -c mj.txt
36 mj.txt

cut 切割

-d:指定分隔符
-f:指定字段

[root@tenor ~]# cut --help
Usage: cut OPTION... [FILE]...
#以:为分隔符显示这个文件中第七个字符创
[root@tenor ~]# cut -d: -f7 /tmp/passwd.output  
/BIN/BASH
/SBIN/NOLOGIN
/SBIN/NOLOGIN
/SBIN/NOLOGIN
/SBIN/NOLOGIN

sort:排序

-f:忽略大小写
-r:逆序
-t:字符分隔符
-k # :以指定字段为标准排序
-n:以数字排序(默认以字符排序)
-u:排序后去重

uniq命令 :去重

-c:显示每行出现的次数
-d:仅显示重复过的行
-u:仅显示未重复的行

综合案例:以:为分割,取出/etc/passwd文件的第6列至第10列,并将这些信息按照第3个字段的数值大小进行排序,最后仅显示一个字段
 [root@tenor ~]#  cut -d : -f6-10 /etc/passwd  |cut -f3 | sort -n | uniq -c  
      1 /bin:/sbin/nologin
      1 /etc/abrt:/sbin/nologin
      1 /etc/ntp:/sbin/nologin
      1 /home/lars:/bin/bash
      1 /home/syslog:/bin/false
      1 /root:/bin/bash
      1 /root:/sbin/nologin
      1 /sbin:/bin/sync
      5 /:/sbin/nologin
      1 /sbin:/sbin/halt
      1 /sbin:/sbin/nologin
      1 /sbin:/sbin/shutdown
      1 /usr/games:/sbin/nologin
      1 /var/adm:/sbin/nologin
      1 /var/empty/sshd:/sbin/nologin
      1 /var/ftp:/sbin/nologin
      1 /var/lib/chrony:/sbin/nologin
      1 /var/lib/rpcbind:/sbin/nologin
      1 /var/run/lsm:/sbin/nologin
      1 /var/spool/lpd:/sbin/nologin
      1 /var/spool/mail:/sbin/nologin
      1 /var/spool/postfix:/sbin/nologin

paste 合并文件

把每个文件以列对列的方式,一列列地加以合并成一个文件。

-d 默认域的分隔符是空格或tab键,设置新的域分隔符
-s 将每个文件粘贴成一行
从标准输入中读取数据
[root@lhuan ~]# cat 1.sh 
Sun Oct 11 10:50:00 CST 2020
Mon Oct 12 19:27:15 CST 2020
Mon Oct 12 19:27:48 CST 2020
Sun Nov  1 08:56:37 CST 2020
[root@lhuan ~]# cat 2.sh 
#!/bin/bash/
var='https://blog.csdn.net/butterfly5211314/article/details/83095084'
echo "${var##*/}"

##合并
[root@lhuan ~]# paste 1.sh 2.sh 
Sun Oct 11 10:50:00 CST 2020    #!/bin/bash/
Mon Oct 12 19:27:15 CST 2020    var='https://blog.csdn.net/butterfly5211314/article/details/83095084'
Mon Oct 12 19:27:48 CST 2020    echo "${var##*/}"
Sun Nov  1 08:56:37 CST 2020    

##中间用+为分隔符
[root@lhuan ~]# paste -d'+' 1.sh 2.sh 
Sun Oct 11 10:50:00 CST 2020+#!/bin/bash/
Mon Oct 12 19:27:15 CST 2020+var='https://blog.csdn.net/butterfly5211314/article/details/83095084'
Mon Oct 12 19:27:48 CST 2020+echo "${var##*/}"
Sun Nov  1 08:56:37 CST 2020+

comm 对比文件

参数 说明
-1 不显示只在第一个文件中出现的列
-2 不显示只在第二个文件中出现的列
-3 不显示只在第一和第二个文件中出现的列
[root@lhuan ~]# cat 1.sh 
Sun Oct 11 10:50:00 CST 2020
Mon Oct 12 19:27:15 CST 2020
Mon Oct 12 19:27:48 CST 2020
Sun Nov  1 08:56:37 CST 2020
[root@lhuan ~]# cat 2.sh 
#!/bin/bash/
var='https://blog.csdn.net/butterfly5211314/article/details/83095084'
echo "${var##*/}"


##只删除1.sh中的内容
[root@lhuan ~]# comm -1 1.sh 2.sh
#!/bin/bash/
comm: file 1 is not in sorted order
var='https://blog.csdn.net/butterfly5211314/article/details/83095084'
comm: file 2 is not in sorted order
echo "${var##*/}"

##只删除2.sh中的内容
[root@lhuan ~]# comm -2 1.sh 2.sh
Sun Oct 11 10:50:00 CST 2020
comm: file 1 is not in sorted order
Mon Oct 12 19:27:15 CST 2020
Mon Oct 12 19:27:48 CST 2020
Sun Nov  1 08:56:37 CST 2020
comm: file 2 is not in sorted order

##只删除两个文件共有的部分
[root@lhuan ~]# comm -3 1.sh 2.sh
    #!/bin/bash/
Sun Oct 11 10:50:00 CST 2020
comm: file 1 is not in sorted order
Mon Oct 12 19:27:15 CST 2020
Mon Oct 12 19:27:48 CST 2020
Sun Nov  1 08:56:37 CST 2020
    var='https://blog.csdn.net/butterfly5211314/article/details/83095084'
comm: file 2 is not in sorted order
    echo "${var##*/}"