欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

linux系統(tǒng)中find命令的exec怎么用

這篇文章主要介紹linux系統(tǒng)中find命令的exec怎么用,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

成都創(chuàng)新互聯(lián)公司為企業(yè)級客戶提高一站式互聯(lián)網(wǎng)+設計服務,主要包括成都網(wǎng)站設計、成都網(wǎng)站制作、重慶App定制開發(fā)小程序設計、宣傳片制作、LOGO設計等,幫助客戶快速提升營銷能力和企業(yè)形象,創(chuàng)新互聯(lián)各部門都有經(jīng)驗豐富的經(jīng)驗,可以確保每一個作品的質(zhì)量和創(chuàng)作周期,同時每年都有很多新員工加入,為我們帶來大量新的創(chuàng)意。 

find是我們很常用的一個Linux命令,但是我們一般查找出來的并不僅僅是看看而已,還會有進一步的操作,這個時候exec的作用就顯現(xiàn)出來了。

exec解釋:

-exec  參數(shù)后面跟的是command命令,它的終止是以;為結(jié)束標志的,所以這句命令后面的分號是不可缺少的,考慮到各個系統(tǒng)中分號會有不同的意義,所以前面加反斜杠。

{}   花括號代表前面find查找出來的文件名。

使用find時,只要把想要的操作寫在一個文件里,就可以用exec來配合find查找,很方便的。在有些操作系統(tǒng)中只允許-exec選項執(zhí)行諸如l s或ls -l這樣的命令。大多數(shù)用戶使用這一選項是為了查找舊文件并刪除它們。建議在真正執(zhí)行rm命令刪除文件之前,最好先用ls命令看一下,確認它們是所要刪除的文件。 exec選項后面跟隨著所要執(zhí)行的命令或腳本,然后是一對兒{ },一個空格和一個\,最后是一個分號。為了使用exec選項,必須要同時使用print選項。如果驗證一下find命令,會發(fā)現(xiàn)該命令只輸出從當前路徑起的相對路徑及文件名。

實例1:ls -l命令放在find命令的-exec選項中

命令:

find . -type f -exec ls -l {} \;

輸出:

代碼如下:


[root@localhost test]# find . -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 127 10-28 16:51 ./log2014.log
-rw-r--r-- 1 root root 0 10-28 14:47 ./test4/log3-2.log
-rw-r--r-- 1 root root 0 10-28 14:47 ./test4/log3-3.log
-rw-r--r-- 1 root root 0 10-28 14:47 ./test4/log3-1.log
-rw-r--r-- 1 root root 33 10-28 16:54 ./log2013.log
-rw-r--r-- 1 root root 302108 11-03 06:19 ./log2012.log
-rw-r--r-- 1 root root 25 10-28 17:02 ./log.log
-rw-r--r-- 1 root root 37 10-28 17:07 ./log.txt
-rw-r--r-- 1 root root 0 10-28 14:47 ./test3/log3-2.log
-rw-r--r-- 1 root root 0 10-28 14:47 ./test3/log3-3.log
-rw-r--r-- 1 root root 0 10-28 14:47 ./test3/log3-1.log
[root@localhost test]#

說明:

上面的例子中,find命令匹配到了當前目錄下的所有普通文件,并在-exec選項中使用ls -l命令將它們列出。

實例2:在目錄中查找更改時間在n日以前的文件并刪除它們

命令:

find . -type f -mtime +14 -exec rm {} \;

輸出:

代碼如下:


[root@localhost test]# ll
總計 328
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
-rw-r--r-- 1 root root     33 10-28 16:54 log2013.log
-rw-r--r-- 1 root root    127 10-28 16:51 log2014.log
lrwxrwxrwx 1 root root      7 10-28 15:18 log_link.log -> log.log
-rw-r--r-- 1 root root     25 10-28 17:02 log.log
-rw-r--r-- 1 root root     37 10-28 17:07 log.txt
drwxr-xr-x 6 root root   4096 10-27 01:58 scf
drwxrwxrwx 2 root root   4096 10-28 14:47 test3
drwxrwxrwx 2 root root   4096 10-28 14:47 test4
[root@localhost test]# find . -type f -mtime +14 -exec rm {} \;
[root@localhost test]# ll
總計 312
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
lrwxrwxrwx 1 root root      7 10-28 15:18 log_link.log -> log.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]#

說明:

在shell中用任何方式刪除文件之前,應當先查看相應的文件,一定要小心!當使用諸如mv或rm命令時,可以使用-exec選項的安全模式。它將在對每個匹配到的文件進行操作之前提示你。

實例3:在目錄中查找更改時間在n日以前的文件并刪除它們,在刪除之前先給出提示

命令:

find . -name "*.log" -mtime +5 -ok rm {} \;

輸出:

代碼如下:


[root@localhost test]# ll
總計 312
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log
lrwxrwxrwx 1 root root      7 10-28 15:18 log_link.log -> log.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 . -name "*.log" -mtime +5 -ok rm {} \;
< rm ... ./log_link.log > ? y
< rm ... ./log2012.log > ? n
[root@localhost test]# ll
總計 312
-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.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命令在當前目錄中查找所有文件名以.log結(jié)尾、更改時間在5日以上的文件,并刪除它們,只不過在刪除之前先給出提示。 按y鍵刪除文件,按n鍵不刪除。

實例4:-exec中使用grep命令

命令:

find /etc -name "passwd*" -exec grep "root" {} \;

輸出:

代碼如下:


[root@localhost test]# find /etc -name "passwd*" -exec grep "root" {} \;
root:x:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
[root@localhost test]#

說明:

任何形式的命令都可以在-exec選項中使用。  在上面的例子中我們使用grep命令。find命令首先匹配所有文件名為“ passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后執(zhí)行grep命令看看在這些文件中是否存在一個root用戶。

實例5:查找文件移動到指定目錄 

命令:

find . -name "*.log" -exec mv {} .. \;

輸出:

代碼如下:


[root@localhost test]# ll
總計 12drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxr-x 2 root root 4096 11-12 22:49 test3
drwxrwxr-x 2 root root 4096 11-12 19:32 test4
[root@localhost test]# cd test3/
[root@localhost test3]# ll
總計 304
-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
[root@localhost test3]# find . -name "*.log" -exec mv {} .. \;
[root@localhost test3]# ll
總計 0[root@localhost test3]# cd ..
[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:50 test3
drwxrwxr-x 2 root root   4096 11-12 19:32 test4
[root@localhost test]#

實例6:用exec選項執(zhí)行cp命令 

命令:

find . -name "*.log" -exec cp {} test3 \;

輸出:

代碼如下:


[root@localhost test3]# ll
總計 0[root@localhost test3]# cd ..
[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:50 test3
drwxrwxr-x 2 root root   4096 11-12 19:32 test4
[root@localhost test]# find . -name "*.log" -exec cp {} test3 \;
cp: “./test3/log2014.log” 及 “test3/log2014.log” 為同一文件
cp: “./test3/log2013.log” 及 “test3/log2013.log” 為同一文件
cp: “./test3/log2012.log” 及 “test3/log2012.log” 為同一文件
[root@localhost test]# cd test3
[root@localhost test3]# 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 test3]#

以上是“l(fā)inux系統(tǒng)中find命令的exec怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站題目:linux系統(tǒng)中find命令的exec怎么用
文章來源:http://aaarwkj.com/article34/iigpse.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、手機網(wǎng)站建設網(wǎng)站設計公司、關鍵詞優(yōu)化、網(wǎng)站內(nèi)鏈、App設計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
国产胖中年妇女草逼网站| 亚洲无人区码一码二码三码| 日本一区二区三区免费精品| 日本精品在线不卡视频| 国产亚洲精品免费专线视频| 亚洲av永久精品一区二区三区| 国产高清在线a视频大全| 精品久久久久久久久无| 刘亦菲毛片一区二区三区| 国产丝袜在线精品丝袜不卡| 精品国产91高清在线观看| 午夜福利激情视频在线| 精品久久久久久久中文字幕| 日本欧美高清一区二区| 精品久久av一区二区三区| 亚洲天堂免费在线播放| 男女搞j视频网站免费观看| 中文字幕日韩人妻av| 午夜福利视频欧美成人| 蜜臀av午夜福利在线观看| 一区二区三区成人高清视频| 久久夜色噜噜噜av一区| 国产中文字幕一区久久| 日本三级黄色免费的网站| 日韩精品中文字幕人妻系列| 免费可以看的黄片欧美| 中文字幕一区二区三区不卡日日| 人妻艳情一区二区三区| 亚洲国产一区二区三区三州| 老熟妇仑乱换频一区二区| 中国一区二区三区毛片| 人人爽人人妻人人澡| 九九久久精品久久久精品| 中文字幕日韩欧美一区在线| 日本不卡视频二区三区| sedoge在线播放免费有码| 亚洲欧美另类重口国产| 国产av综合一区二区三区最新| 亚洲中文永久免费视频| 亚洲精品一区二区三区高清| 日本av人妻在线观看|