xargs 應用實例

find:

1.find  /home/linux -name ".txt" -print
2.find  . \(-name "*.txt" -o -name "*.pdf" \) -print  (-o=or)
3.find  /home/linux -path "*slinux" -print
4.find  . -regex ".*\(\.py\|\.sh\)$"
5.find  . ! -name "*.txt" -print

find  .-maxdepth l -type f -print
find  . -type d
find  . -type f

find  . -type f -atime -7 -print
find  . -type f -atime +7 -print
find  . -type f -newer file.txt -print (find  update file for the  one)
find  . -type f -size -2k
find  . -type f perm 644 -print


find  . -type f -user root -exec chown {} \
find  . -type f -mtime +10 -name "*.txt" -exec cp {} OLD \
find  /home/linux \(-name ".git" -prune\) -o \(-type f -print\)



xargs:

cat file.txt|xargs -n 3
echo "abdXcdsXcdcdX"|xargs -d X -n 2
abd cds
cdcd
-------------------------------------------------------
./cecho arg1 arg2 arg3
cat file.txt|xargs -n 1 ./cecho.sh
cat file.txt|xargs -n 2 ./cecho.sh
cat file.txt|xargs ./cecho.sh

cat args.txt|xargs -I {} ./cecho.sh -p {} -l

find  . -type f -name "*type" -print 0|xargs -0 rm -f
find  . -type f -name  exclude.cdnRsync -exec cat {} \;

find  . -type f -name  exclude.cdnRsync -exec cat {} \|xargs rm -f;
 

 

 

$ ls | xargs -t -i mv {} {}.bak
-i 選項告訴 xargs 用每項的名稱替換 {}。-t 選項指示 xargs 先打印命令,然後再執行。
 

$ file * | grep ASCII | cut -d":" -f1 | xargs -p vi vi alert_DBA102.log dba102_cjq0_14493.trc dba102_mmnl_14497.trc
dba102_reco_14491.trc dba102_rvwr_14518.trc ?...
此處的 xarg 要求您在運行每個命令之前進行確認。如果您按下 "y",則執行命令。當您對文件進行某些可能有破壞且不可恢復的操作(如刪除或覆蓋)時,您會發現該選項非常有用。
 

 

 

 

 

 

 

 

 



 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章