標籤:
1.xargs複製檔案
目錄下檔案結構為:
.├── demo1│ ├── test.lua│ ├── test.php│ └── test.txt└── demo2
執行命令:
find ./demo1/ -name ‘test*‘|cp `xargs` ./demo2/
目錄結構為:
.├── demo1│ ├── test.lua│ ├── test.php│ └── test.txt└── demo2 ├── test.lua ├── test.php └── test.txt
2.xargs複製檔案
[[email protected] xargsTest]# tree.├── demo1│ ├── test.lua│ ├── test.php│ └── test.txt└── demo2 ├── test.lua ├── test.php └── test.txtfind ./demo1/ -name ‘test*‘|xargs -i cp {} {}.bak.├── demo1│ ├── test.lua│ ├── test.lua.bak│ ├── test.php│ ├── test.php.bak│ ├── test.txt│ └── test.txt.bak└── demo2 ├── test.lua ├── test.php └── test.txt
3.xargs刪除檔案
查詢以.bak結尾的檔案
find ./demo1/ -name ‘*.bak‘
./demo1/test.txt.bak./demo1/test.lua.bak./demo1/test.php.bak
刪除這些檔案
find ./demo1/ -name ‘*.bak‘|xargs rm -fr
[[email protected] xargsTest]# tree.├── demo1│ ├── test.lua│ ├── test.php│ └── test.txt└── demo2 ├── test.lua ├── test.php └── test.txt
刪除成功
xargs命令學習