使用find 命令执行命令 -exec

介绍 -exec 参数

如果-exec执行的过程中,执行的命令执行异常,后面的文件还会继续执行吗?

答案是

做一个简单的实验证明之:、
首先文件夹下内容

root@e2e1e45edb7a:~/test#  ls -l
总用量 104
-rw-r--r-- 1 root root    15 7月  27 02:25 o
-rwxr-xr-x 1 root root 97408 7月  27 02:25 ps
-rw-r--r-- 1 root root    11 7月  27 02:27 q

只有ps是可执行文件,其他两个都是普通文件。

我们用 readelf 命令测试,readelf 命令可以读取二进制文件。
但是遇到普通文件会提示错误

root@e2e1e45edb7a:~/test# readelf -s  o
readelf:错误: o:读入文件头失败

find 命令返回结果按照字母排序,所以ps可执行文件是第二个。

root@e2e1e45edb7a:~/test# find ./ -type f -exec readelf -h {} \;
readelf:错误: ./o:读入文件头失败
ELF 头:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  类别:                              ELF64
  数据:                              2 补码,小端序 (little endian)
  版本:                              1 (current)
  OS/ABI:                            UNIX - System V
  ABI 版本:                          0
  类型:                              EXEC (可执行文件)
  系统架构:                          Advanced Micro Devices X86-64
  版本:                              0x1
  入口点地址:               0x402f10
  程序头起点:          64 (bytes into file)
  Start of section headers:          95552 (bytes into file)
  标志:             0x0
  本头的大小:       64 (字节)
  程序头大小:       56 (字节)
  Number of program headers:         9
  节头大小:         64 (字节)
  节头数量:         29
  字符串表索引节头: 28
readelf:错误: ./q:读入文件头失败

发现可以顺利执行全部文件命令,不会因为 readelf -h o 出错就停止执行。

猜你喜欢

转载自blog.csdn.net/qq_21063873/article/details/81235098