好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > linux find命令之xargs簡單概述

linux find命令之xargs簡單概述

熱門標簽:智能電銷機器人有用嗎 德陽400電話申請 百度地圖標注直線距離 怎么在百度地圖標注公司的位置 商機地圖標注 外呼電話系統怎么操作 天津電話外呼系統排名 鶴崗400電話申請 測繪地圖標注名稱

在使用 find命令的-exec選項處理匹配到的文件時, find命令將所有匹配到的文件一起傳遞給exec執行。但有些系統對能夠傳遞給exec的命令長度有限制,這樣在find命令運行幾分鐘之后,就會出現溢出錯誤。錯誤信息通常是“參數列太長”或“參數列溢出”。這就是xargs命令的用處所在,特別是與find命令一起使用。

find命令把匹配到的文件傳遞給xargs命令,而xargs命令每次只獲取一部分文件而不是全部,不像-exec選項那樣。這樣它可以先處理最先獲取的一部分文件,然后是下一批,并如此繼續下去。

在有些系統中,使用-exec選項會為處理每一個匹配到的文件而發起一個相應的進程,并非將匹配到的文件全部作為參數一次執行;這樣在有些情況下就會出現進程過多,系統性能下降的問題,因而效率不高; 而使用xargs命令則只有一個進程。另外,在使用xargs命令時,究竟是一次獲取所有的參數,還是分批取得參數,以及每一次獲取參數的數目都會根據該命令的選項及系統內核中相應的可調參數來確定。

使用實例:

實例1: 查找系統中的每一個普通文件,然后使用xargs命令來測試它們分別屬于哪類文件

命令:

find . -type f -print | xargs file

輸出:

[root@localhost test]# ll
總計 312
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2013.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxrwx 2 root root 4096 11-12 19:32 test3
drwxrwxrwx 2 root root 4096 11-12 19:32 test4
[root@localhost test]# find . -type f -print | xargs file
./log2014.log: empty
./log2013.log: empty
./log2012.log: ASCII text
[root@localhost test]#

實例2:在整個系統中查找內存信息轉儲文件(core dump) ,然后把結果保存到/tmp/core.log 文件中

命令:

 find / -name "core" -print | xargs echo "" >/tmp/core.log

輸出:

[root@localhost test]# find / -name "core" -print | xargs echo "" >/tmp/core.log
[root@localhost test]# cd /tmp
[root@localhost tmp]# ll
總計 16
-rw-r--r-- 1 root root 1524 11-12 22:29 core.log
drwx------ 2 root root 4096 11-12 22:24 ssh-TzcZDx1766
drwx------ 2 root root 4096 11-12 22:28 ssh-ykiRPk1815
drwx------ 2 root root 4096 11-03 07:11 vmware-root

實例3:在當前目錄下查找所有用戶具有讀、寫和執行權限的文件,并收回相應的寫權限

命令:

find . -perm -7 -print | xargs chmod o-w

輸出:

[root@localhost test]# ll
總計 312
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2013.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxrwx 2 root root 4096 11-12 19:32 test3
drwxrwxrwx 2 root root 4096 11-12 19:32 test4
[root@localhost test]# find . -perm -7 -print | xargs chmod o-w
[root@localhost test]# ll
總計 312
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2013.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-12 19:32 test3
drwxrwxr-x 2 root root 4096 11-12 19:32 test4
[root@localhost test]#

說明:

執行命令后,文件夾scf、test3和test4的權限都發生改變

實例4:用grep命令在所有的普通文件中搜索hostname這個詞

命令:

find . -type f -print | xargs grep "hostname"

輸出:

[root@localhost test]# find . -type f -print | xargs grep "hostname"
./log2013.log:hostnamebaidu=baidu.com
./log2013.log:hostnamesina=sina.com
./log2013.log:hostnames=true[root@localhost test]#

實例5:用grep命令在當前目錄下的所有普通文件中搜索hostnames這個詞

命令:

find . -name \* -type f -print | xargs grep "hostnames"


輸出:

[root@peida test]# find . -name \* -type f -print | xargs grep "hostnames"
./log2013.log:hostnamesina=sina.com
./log2013.log:hostnames=true[root@localhost test]#

說明:

注意,在上面的例子中, \用來取消find命令中的*在shell中的特殊含義。

實例6:使用xargs執行mv

命令:

find . -name "*.log" | xargs -i mv {} test4

輸出:

[root@localhost test]# ll
總計 316
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
-rw-r--r-- 1 root root  61 11-12 22:44 log2013.log
-rw-r--r-- 1 root root  0 11-12 22:25 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-12 22:54 test3
drwxrwxr-x 2 root root 4096 11-12 19:32 test4
[root@localhost test]# cd test4/
[root@localhost test4]# ll
總計 0
[root@localhost test4]# cd ..
[root@localhost test]# find . -name "*.log" | xargs -i mv {} test4
[root@localhost test]# ll
總計 12
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 05:50 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]# cd test4/
[root@localhost test4]# ll
總計 304
-rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log
-rw-r--r-- 1 root root  61 11-12 22:54 log2013.log
-rw-r--r-- 1 root root  0 11-12 22:54 log2014.log
[root@localhost test4]#

實例7:find后執行xargs提示xargs: argument line too long解決方法:

命令:

find . -type f -atime +0 -print0 | xargs -0 -l1 -t rm -f

輸出:

[root@pd test4]# find . -type f -atime +0 -print0 | xargs -0 -l1 -t rm -f
rm -f 
[root@pdtest4]#

說明:

-l1是一次處理一個;-t是處理之前打印出命令

實例8:使用-i參數默認的前面輸出用{}代替,-I參數可以指定其他代替字符,如例子中的[]

命令:

find . -name "file" | xargs -I [] cp [] ..

輸出:

[root@localhost test]# ll
總計 12
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 05:50 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]# cd test4
[root@localhost test4]# find . -name "file" | xargs -I [] cp [] ..
[root@localhost test4]# ll
總計 304
-rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log
-rw-r--r-- 1 root root  61 11-12 22:54 log2013.log
-rw-r--r-- 1 root root  0 11-12 22:54 log2014.log
[root@localhost test4]# cd ..
[root@localhost test]# ll
總計 316
-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root root  61 11-13 06:03 log2013.log
-rw-r--r-- 1 root root  0 11-13 06:03 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 05:50 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]#

說明:

使用-i參數默認的前面輸出用{}代替,-I參數可以指定其他代替字符,如例子中的[]

實例9:xargs的-p參數的使用

命令:

find . -name "*.log" | xargs -p -i mv {} ..

輸出:

[root@localhost test3]# ll
總計 0
-rw-r--r-- 1 root root 0 11-13 06:06 log2015.log
[root@localhost test3]# cd ..
[root@localhost test]# ll
總計 316
-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root root  61 11-13 06:03 log2013.log
-rw-r--r-- 1 root root  0 11-13 06:03 log2014.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 06:06 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]# cd test3
[root@localhost test3]# find . -name "*.log" | xargs -p -i mv {} ..
mv ./log2015.log .. ?...y
[root@localhost test3]# ll
總計 0
[root@localhost test3]# cd ..
[root@localhost test]# ll
總計 316
-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log
-rw-r--r-- 1 root root  61 11-13 06:03 log2013.log
-rw-r--r-- 1 root root  0 11-13 06:03 log2014.log
-rw-r--r-- 1 root root  0 11-13 06:06 log2015.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-13 06:08 test3
drwxrwxr-x 2 root root 4096 11-13 05:50 test4
[root@localhost test]#

說明:

-p參數會提示讓你確認是否執行后面的命令,y執行,n不執行。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Linux基礎之xargs命令的入門實例
  • linux中xargs命令的各種使用技巧
  • Linux 下xargs命令詳解及xargs與管道的區別
  • Linux xargs命令詳細介紹
  • linux shell腳本學習xargs命令使用詳解
  • Linux xargs命令的使用

標簽:自貢 滁州 百色 優質小號 武漢 六盤水 丹東 鎮江

巨人網絡通訊聲明:本文標題《linux find命令之xargs簡單概述》,本文關鍵詞  linux,find,命令,之,xargs,簡單,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《linux find命令之xargs簡單概述》相關的同類信息!
  • 本頁收集關于linux find命令之xargs簡單概述的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 学生丰满乳房精油| 你好紧好湿好想cao你视频| 色釉釉网站入口| 欧美黄色免费网址| 鲁丝一区| 软糯小受+趴着+顶撞研磨小说| Asian美鮑欣赏pics| 免费又黄又刺激好看的小说| 嗯啊再深一点| 久久99久久精品99久久综合| 国产欧美久久久久久精品四区借种| 【男男】开荤粗肉-v文》| 亚洲人做受???高潮| 精品黑人一区二区三区久久| 欧美一区二区三区不卡| 美国一级婬片A片大全蓝丝绒 | 视频在线观看免费| 冰漪全套无遮挡图片| 师生婬乱专辑小说| 吸小核| xxdd羞羞答答在线观看| 色戒电影无删除在线观看| 极品嫩苞撕裂哭叫灌白浆在线观看| 国产????BBBB| 美女露出尿口无遮挡| 红桃Av成人免费视频| 中文字幕丰满人妻无码区隔壁人爱| 男女一进一出全过程视频| 搞怪女厨泰剧在线观看| 欧美裸体美女图片| ThePorn在线观看免费播放| 狠狠色综合一区二区| 对室友下药bl文肉| chinesefreexxxx护士| 公交上配合陌生人弄到高c| 国产精品第100页| 欧美人马交| 公交车破了两个六年小学生3| 公与淫两个荡乱| 99久久精品国产99久久久久久禁果| 国产精品秘?黄动漫视频|