2021-11-9-linux-echo命令

1.tee 命令

两个方向的重定向——指定路径+屏幕

默认是覆盖旧内容的,使用选项-a 实现追加重定向
2.echo

echo在默认情况下是换行的,就像前文也有提到过类似print
可以运用选项-n取消换行

[root@lamp-test lianxi]# echo "ee"
ee
[root@lamp-test lianxi]# echo -n "ee"
ee[root@lamp-test lianxi]# 

选项-e恢复转义字符功能

xargs命令:把前面的输出变成后面的参数

[root@jack lianxi]# echo hj.txt|xargs ls -l
-rw-r--r--. 1 root root 175 11月  8 11:04 hj.txt

3.seq 命令

[root@jack lianxi]# seq 4
1
2
3
4
[root@jack lianxi]# seq 4  10
4
5
6
7
8
9
10
[root@jack lianxi]# seq 4 +2 10
4
6
8
10

可以和for循环结合控制循环次数

4.tr命令—替换

  • tr 原内容 替换内容
[root@jack lianxi]# echo 1123321434|tr 123 abc
aabccba4c4
  • <结合使用替换文件内容
[root@jack lianxi]# cat xixixi.txt 
1234567
[root@jack lianxi]# tr 123 abc <xixixi.txt 
abc4567

-d选项 删除指定内容

[root@jack lianxi]# a='12345'
[root@jack lianxi]# echo $a
12345
[root@jack lianxi]# echo $a|tr -d 14
235
[root@jack lianxi]# echo $a
12345

很明显,不会改变原值

-s选项 压缩
tr -s 压缩内容

[root@jack lianxi]# echo 11111111111122222222222333333333333333xdsxfffffffffffs|tr -s 123
123xdsxfffffffffffs
[root@jack lianxi]# echo 11111111111122222222222333333333333333xdsxfffffffffffs|tr -s 123f
123xdsxfs

统计关键词个数的方法:

  • 使用grep

grep 的-o选项可以只显示含此内容的文本并换行

[root@jack lianxi]# cat xixixi.txt |grep -o ':'|wc -l
5
  • 使用tr
    直接用换行符替换文本的分隔符后再统计,直接用grep更简便

grep补充:

grep “a$” 过滤a结尾的内容
grep “^a” 过滤a开头的内容

5.sort命令

for排序

  • -n 按整数进行排序–>默认是升序
  • -r 递减排序
  • -t 指定字段分割符
  • -u 去重
  • -k 指定哪一列为排序键

6.uniq命令

去重

  • -c 去重并计数
[root@jack lianxi]# df -Th|awk '{print $1}'|uniq -c 
      1 文件系统
      1 devtmpfs
      3 tmpfs
      1 /dev/mapper/cl-root
      1 /dev/sda1
      1 tmpfs
  • -d 显示有重复的内容
[root@jack lianxi]# df -Th|awk '{print $1}'|uniq -d
tmpfs

7.cut命令

剪切

  • -c 按字符来剪
    -c4-7从第四个剪到第七个
    -c4,7剪第四个和第七个
    -c4 剪第四个
    -c4-从第四个开始剪到最后
  • -f 选择列
  • -d 指定分隔符
[root@jack lianxi]# df -Th
文件系统            类型      容量  已用  可用 已用% 挂载点
devtmpfs            devtmpfs  876M     0  876M    0% /dev
tmpfs               tmpfs     896M     0  896M    0% /dev/shm
tmpfs               tmpfs     896M   17M  879M    2% /run
tmpfs               tmpfs     896M     0  896M    0% /sys/fs/cgroup
/dev/mapper/cl-root xfs        17G  7.3G  9.8G   43% /
/dev/sda1           xfs      1014M  193M  822M   19% /boot
tmpfs               tmpfs     180M     0  180M    0% /run/user/0
[root@jack lianxi]# df -Th|cut -d 'M' -f 1
文件系统            类型      容量  已用  可用 已用% 挂载点
devtmpfs            devtmpfs  876
tmpfs               tmpfs     896
tmpfs               tmpfs     896
tmpfs               tmpfs     896
/dev/mapper/cl-root xfs        17G  7.3G  9.8G   43% /
/dev/sda1           xfs      1014
tmpfs               tmpfs     180

猜你喜欢

转载自blog.csdn.net/kapri/article/details/121452002