Linux--RH134---unit 6 linux中常用的基础命令

xiaoxiao2021-02-27  453

linux中常用的基础命令

1.diff

diff file file1                                ##显示两个文件的不同

diff -c file file1                             ##显示两个文件不同之处的前后几行

diff -u file file1 >file.path      ##生成补丁文件.path yum install patch -y               ##安装打补丁工具

patch   file file.path                         ##给老文件打补丁,新文件取代老文件

patch   -b file file.path         ##给老文件打补丁,且对文软件进行备份生成.orig文件 2.grep

grep 关键字  file              ##搜索字符

grep -i关键字  file               ##忽略大小写搜索

grep 关键字  file -n               ##显示结果所在行的行号 grep 关键字  file -c               ##显示具有匹配模式的行数

grep 关键字  file -v               ##反向过滤

grep -r 关键字 目录                        ##在目录中过滤含有关键字的文件

grep 关键字  file -E"关键字1|关键字2|....."  ##过滤多个关键字

grep ^关键字 file                              ##过滤以关键字开头 grep 关键字$ file                              ##过滤以关键字结尾

3.sort

    sort file                                      ##排第一个字符顺序

sort file -n                       ##数值排序

sort file -r                       ##倒序

sort file -u                       ##去掉重复行

                -t              ##指定分隔符                 -k             ##指定排序的列

4.uniq                     ##处理重复行

        -c              ##每行显示一次,包括出现计数         -u              ##显示唯一的行         -d              ##显示重复行

5.tr                       ##转换字符大小写 tr 'a-z' 'A-Z'  <file              ##file中所有小写字符转换成大写 tr 'A-Z' 'a-z'  <file              ##file中所有大写字符转换成小写

6.sed                          ##控制流输出 sed 's/nologin/westos/g' passwd               ##替换输出中的nologinwestos

sed 's/nologin/westos/g' -i passwd                      ##替换后的结果输入到passwd

sed '1,5s/nologin/westos/g' passwd             ##替换输出中1-5行的nologinwesots

sed -e 's/nologin/westos/g' -e 's/sbin/linux/g' passwd ##多条替换策略用-e连接 

vim rule                ##规则文件内容 s/nologin/westos/g s/sbin/linux/g sed -f rule  file           ##使用规则文件更改输出      1  root:x:0:0:root:/root:/bin/bash      2  bin:x:1:1:bin:/bin:/linux/westos      3  daemon:x:2:2:daemon:/linux:/linux/westos      4  adm:x:3:4:adm:/var/adm:/linux/westos

sed 3x passwd                      ##文件中的第三行为空 

sed 3d passwd                      ##不显示文件中的第三行

sed 3p passwd                      ##重复显示文件中的第三行 

sed 3,7d file                      ##不显示文件中的3-7 

sed 3,7p file                      ##重复显示文件中的3-7

sed -n 3p file                                          ##只显示文件中的第三行 sed -n 3,7p file                   ##只显示文件中的3-7 sed -ne 3p -ne 7p file                 ##只显示文件中的37 7.cut cut -d : -f 1 passwd                       ##只显示文件第一列 cut -d : -f 1,3 passwd                     ##只显示文件13

cut -d : -f 1-3 passwd                     ##只显示文件1-3

cut -c 2-4 passwd                          ##只显示文件每行第2-4个字符

8.awk awk  -F ":" '{print $n}'                   ##只显示第n个域  

转载请注明原文地址: https://www.6miu.com/read-693.html

最新回复(0)