day03

1.输出重定向的案例

类型 操作符 用途
标准覆盖输出重定向 > 将程序输出的正确结果输出到指定的文件中,会覆盖文件原有的内容
标准追加输出重定向 >> 将程序输出的正确结果以追加的方式输出到指定的文件中,不会覆盖文件原有的内容
错误覆盖输出重定向 2> 将程序的错误结果输出到执行的文件中,会覆盖文件原有的内容
错误追加输出重定向 2>> 将程序输出的错误结果以追加的方式输出到指定的文件中,不会覆盖文件原有的内容

 1.1

①正确输出及错误输出至相同的文件

②正确输出及错误输出至不同的文件

1.2

正确输出及错误输出混合至同一文件

将两个文件内容组合为一个文件

2.管道

2.1将/etc/passwd 中的用户按UID大小排序

2.2 统计当前/etc/passwd中用户使用的shell类型

2.3打印当前所有的IP

2.4 tee和xargs

2.4.1 tee

[root@cent7os  ~]#date  > date.txt      #直接写入到date文件中
[root@cent7os  ~]#date  | tee  date.txt    #命令执行输出到屏幕。并会同时保存到date文件

2.4.2 xargs参数传递

让一些不支持管道的命令可以使用管道技术

3.find

3.1基于名称查找

 ~]# find   /etc   -name  "ifcfg-ens32"
/etc/sysconfig/network-scripts/ifcfg-ens32

]# find /etc -iname "ifcfg-ens3*"
/etc/sysconfig/network-scripts/ifcfg-ens32
/etc/sysconfig/network-scripts/IFCFG-ENS33

3.2 基于大小查找

# find   /etc   -size  +5M      大于5m
/etc/udev/hwdb.bin
# find   /etc   -size  5M       等于5M
#
find /etc -size -5M        小于5M

 3.3 基于类型查找

find  /dev  -type   f
#f 文件 d 目录   l 链接  b 块设备  c 字符设备  s 套接字  p 管道文件

3.4 基于时间查找

 

 案例

# for  i in  {01..10};do date  -s  202004$i  &&  touch file-$i;done

# find ./ -iname "file-*" -mtime +7
./file-01
./file-02

# find ./ -iname "file-*" -mtime -7
./file-04
./file-05
./file-06
./file-07
./file-08
./file-09
./file-10

# find ./ -iname "file-*" -mtime 7
./file-03

查找/var/log  下所有的以  .log结尾的文件,并保留最近7天的文件

3.5 基于用户查找

#属主是jack,属组是admin    或者用-o  
find
/home -user jack -a -group admin

3.6 基于权限查找

#find    /root        -type    f        -perm    644    -ls    #精准查找
#find    /root        -type    f        -perm    -644    -ls    #包含权限查找

3.7 逻辑运算符

 

 

posted @ 2022-05-05 20:43  mmniu  阅读(31)  评论(0)    收藏  举报