假設我有多個檔案,例如:
root.file991
root.file81
root.file77
root.file989
如果我想洗掉所有這些,我需要先使用正則運算式,所以我嘗試了:
find ./ - regex '\.\/root'
...這將在根檔案中找到所有內容,但是如何過濾所有這些特定檔案?
uj5u.com熱心網友回復:
我不太確定“根檔案中的檔案”是什么意思,但如果我理解正確,常規 POSIXglob(7)模式匹配就足夠了:
rm root.file[0-9]*
uj5u.com熱心網友回復:
您可以使用
find ./ -regextype posix-extended -regex '\./root\.file[0-9] '
正則運算式將匹配路徑,如
\.- 一個點/root\.file- 一段/root.file文字[0-9]- 以一位或多位數字結尾。
uj5u.com熱心網友回復:
根據其他檔案的復雜程度,您可能需要更多地構建正則運算式。$ man find也有有用的幫助。嘗試以下操作:
$ find ./ -regex '\.\/root.file[0-9].*'
# if that works to find what you are looking for, add the -delete
$ find ./ -regex '\.\/root.file[0-9].*' -delete
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/528125.html
