在这里,我想从我的目录和子目录中删除所有的倾斜文件。我如何在这里使用linux命令?
树结构:
.
|-- Block_Physical_design_checklist
| |-- Block_Physical_design_checklist.config
| |-- Block_Physical_design_checklist.html
| |-- Block_Physical_design_checklist.html~
| `-- rev6
| |-- rev6.config
| `-- rev6.html
|-- CAD_checklist
| |-- CAD_checklist.config
| |-- CAD_checklist.html
| |-- CAD_checklist.html~
| `-- rev6
| |-- rev6.config
| `-- rev6.html
|-- Formality_DCT_Vs_ICC
| |-- Formality_DCT_Vs_ICC.config
| |-- Formality_DCT_Vs_ICC.html
| |-- Formality_DCT_Vs_ICC.html~
| `-- rev6
| |-- rev6.config
| |-- rev6.html
| `-- rev6.html~预期树结构:
.
|-- Block_Physical_design_checklist
| |-- Block_Physical_design_checklist.config
| |-- Block_Physical_design_checklist.html
| `-- rev6
| |-- rev6.config
| `-- rev6.html
|-- CAD_checklist
| |-- CAD_checklist.config
| |-- CAD_checklist.html
| `-- rev6
| |-- rev6.config
| `-- rev6.html
|-- Formality_DCT_Vs_ICC
| |-- Formality_DCT_Vs_ICC.config
| |-- Formality_DCT_Vs_ICC.html
| `-- rev6
| |-- rev6.config
| |-- rev6.html发布于 2017-07-05 04:44:45
您的方法find . -type f -name '*~' -exec rm -f '{}' \;有两个问题/改进范围:
-name '*~'只匹配以~结尾的文件;如果要匹配任何包含~的文件,请使用*~*-exec rm -f '{}' \;正在为每个文件生成rm,这是笨拙和低效的;相反,由于rm可以接受多个文件作为参数,您可以告诉find ... -exec一次获得尽可能多的文件,而不使用-exec的+参数触发ARG_MAX。把这两者结合在一起:
find . -type f -name '*~*' -exec rm -f {} +如果碰巧有GNU find,则可以使用-delete操作:
find . -type f -name '*~*' -delete在zsh中,您可以一次执行递归模式匹配和删除,例如:
rm -f -- **/*~*(.)glob修饰符.只匹配常规文件。
发布于 2017-07-05 04:38:43
这是我的答案
find . -type f -name '*~' -exec rm -f '{}' \;发布于 2017-07-05 05:13:10
使用bash的globstar选项:
shopt -s globstar ; rm ./**/*~globstar允许使用**递归全局化,而./则防止文件名中可能包含领先-的问题,而*~将与以tilde结尾的文件名匹配。
https://unix.stackexchange.com/questions/375366
复制相似问题