国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

linux命令find -exec操作的問題

2020-10-14 22:38:23
字體:
來源:轉載
供稿:網友

    最近有這樣一個需求,刪掉某目錄下的一些文件夾。其實就是名為"CVS"的文件夾,用過CVS的人都知道,CVS會在目錄的每一級建立一個名為CVS的文件夾,里面放著CVS相關信息,我需要將某目錄下所有的名為"CVS"的文件夾刪掉。在LINUX下其實很簡單,使用find命令:
    [plain]
    find . -name CVS -exec rm -rf {} /;
    看似沒問題,但卻報錯了:
    [plain]
    find: `./CVS': No such file or directory
    檢查了下,發現其實。/CVS這個文件夾確實存在而且此時已經被刪掉了,算是功德圓滿但是為什么還報錯?
    沒辦法記得find完成這種功能還有一種寫法:
    [plain]
    find . -name CVS -exec rm -rf {} /+
    抱著試試的態度,令人意外的是,這種方式成功執行,并未報任何錯誤,這就叫人疑惑了,沒辦法只好求助于男人(man)
    -exec command ;
    Execute  command;     true  if 0 status is returned.     All following
    arguments to find are taken to be arguments to the command until
    an  argument  consisting of ';' is encountered.  The string '{}'
    is replaced by the current file name being processed  everywhere
    it occurs in the arguments to the command, not just in arguments
    where it is alone, as in some versions of find.  Both  of     these
    constructions might need to be escaped (with a '/') or quoted to
    protect them from expansion by the shell.     See the EXAMPLES sec-
    tion  for examples of the use of the '-exec' option.  The speci-
    fied command is run once for each matched file.  The command  is
    executed    in  the     starting  directory.     There are unavoidable
    security problems surrounding  use  of  the  -exec  option;  you
    should use the -execdir option instead.
    另外一種:
    -exec command {} +
    This  variant  of the -exec option runs the specified command on
    the selected files, but the command line is built     by  appending
    each  selected file name at the end; the total number of invoca-
    tions of the command will     be  much  less     than  the  number  of
    matched  files.    The command line is built in much the same way
    that xargs builds its command lines.  Only one instance of  '{}'
    is  allowed  within the command.    The command is executed in the
    starting directory.
    看了半天我注意到他們的區別,紅字體標注。
    也就是說 "-exec" + ";" 為每一個匹配的文件都執行了一次命令,具體到此處就是 rm -rf 命令,而 "-exec" + "+" 只是把匹配的文件名作為命令的參數append到命令后面,即是這樣: rm -rf file1 file2 file3
    可是這種差別為什么會導致如此明顯的差異呢? 想了想, 悟到了:
(責任編輯:VEVB)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 迭部县| 铜鼓县| 银川市| 内黄县| 宿州市| 龙江县| 南汇区| 永昌县| 兴文县| 贡嘎县| 元江| 枞阳县| 普格县| 屯留县| 荔波县| 苏尼特右旗| 黄浦区| 滨海县| 云阳县| 临武县| 库伦旗| 临夏市| 兴仁县| 丰城市| 怀集县| 山阴县| 永年县| 保山市| 清河县| 故城县| 阳春市| 西吉县| 中宁县| 闵行区| 昆明市| 乐陵市| 介休市| 文成县| 开江县| 泽州县| 深泽县|