linux exec和xargs的區別

2022-08-19 11:54:10 字數 842 閱讀 8824

-exec

1.引數是乙個乙個傳遞的,傳遞乙個引數執行一次,效率低

2.檔名有空格等特殊字元也能處理

-xargs  

1.一次將引數傳給命令,可以使用-n控制引數個數

2.處理特殊檔名需要採用如下方式:find . -name "*.txt" -print0 |xargs -0 rm {}  

技巧: find -print0  與 xargs -0 的結合避免檔名有特殊字元如空格,引號等無法處理:

3.有些命令不支援多個引數,需要用-n 1

eg:mkdir test

cd test

touch .txt

vi test.sh

#!/bin/bash

echo "there is $# parameters."

echo "rm $@"

rm "$@"

echo "pid is $$"

find . -name "*.txt"  -exec echo {} \;

find . -name "*.txt" |xargs  echo

find . -name "*.txt" |xargs -n 1 echo

find . -regextype posix-egrep -regex "./[0-9].txt" -exec ./test.sh {} \;

find . -regextype posix-egrep -regex "./[0-9].txt" -exec ./test.sh {} +

find . -regextype posix-egrep -regex "./[0-9].txt" |xargs ./test.sh

xargs筆記 xargs和mv配合

將所有子目錄裡的txt檔案移動到當前目錄。d installer 2 321.txt 新建資料夾 1.txt 新建資料夾 fds.txtfind mindepth 2 name txt xargs i file mv file 原理 find命令便令當前目錄,通過 mindepth 2排除當前層級。...

linux exec用法總結

2011 01 31 23 48 29 分類 linux技術 標籤 舉報 字型大小大中 小訂閱先總結乙個表 exec命令 作用 exec ls 在shell 中執行ls,ls 結束後不返回原來的 shell中了 exec 將file 中的內容作為 exec 的標準輸入 exec file 將file...

linux exec函式家族

1.exec家族一共有六個函式,分別是 1 int execl const char path,const char arg,2 int execle const char path,const char arg,char const envp 3 int execv const char path...