【问题标题】:find command is able to find the directories but find with -exec rm -r is not able to deletefind 命令能够找到目录,但使用 -exec rm -r 查找无法删除
【发布时间】:2014-04-11 07:05:20
【问题描述】:

我正在运行这个查找命令

find . -mindepth 3 -name [1-9]* -type d 

及其返回一组结果 喜欢

./B*********/*/output/simulation/9
./B********/*/output/simulation/8
./B********/*/output/simulation/7
./B********/*/output/simulation/5
./B********/*/output/simulation/6
./B********/*/output/simulation/4

现在当我跑步时

find . -mindepth 3 -name [1-9]* -type d -exec rm -r {} \; 

在同一个目录

find :./B*********/*/output/simulation/9  No such file or directory
find :./B********/*/output/simulation/8    No such file or directory
find :./B********/*/output/simulation/7    No such file or directory
find :./B********/*/output/simulation/5    No such file or directory
find :./B********/*/output/simulation/6    No such file or directory
find :./B********/*/output/simulation/4    No such file or directory

知道怎么回事

P.S 为了保密起见,我使用 * 来隐藏文件名

【问题讨论】:

  • 你希望[1-9]*find处理,而不是shell,所以你需要引用它,否则你可能会得到不准确的输出,find . -mindepth 3 -name '[1-9]*' -type d -exec rm -r {} \;

标签: shell unix find


【解决方案1】:

{} 周围的引号试试这个查找:

find . -mindepth 3 -name [1-9]* -type d -exec rm -rf '{}' \;

【讨论】:

  • 是否有任何 shell 设置实际上会导致这个问题?此外,可能值得在您的命令中删除 -f,这样 OP 就不会意外执行它并得到无提示的 rm
  • rm -r {} 也不会提示用户,如果这是 OP 想要的,那么他/她将需要 rm -ir '{}'
猜你喜欢
  • 2012-09-19
  • 1970-01-01
  • 1970-01-01
  • 2013-12-14
  • 2016-05-09
  • 1970-01-01
  • 2020-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多