介紹 -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 出錯就停止執行。