shell-find錯誤解析

來源:互聯網
上載者:User

shell-find錯誤解析

之前寫過一篇文章,用shell定時清除到期檔案《shell定時清除到期檔案》,其實用的就是簡單的find命令

後面同事採用之後,他調試指令碼的時候,出現了幾個錯誤,我做了整理:

1.find: paths must precede expression: exec

運算式不完整,在exec之前加一個執行符號“-”,就好了

2.find: missing argument to `-exec'

根據提示,錯誤的參數-exec,其實是提示你運算式錯誤了

原本語句是這樣的“find /var/log/*.log -mtime +30 -exec rm -f {}\;”

解決辦法:在\前面加一個空格,特別注意

解決思路,先去man find找,剛好有find . -type f -exec file '{}' \;

這個解釋夠清楚了:Runs ‘file’ on every file in or below the current directory. Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation. The semicolon is similarly protected by the use of a backslash, though single quotes could have been used in that case also.

--未完待續

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.