Lui*_*cía 13 linux command file
我想清空目录中的所有文件.我试过这个:
find myFolderPath/* -exec cat /dev/null > {} ';'
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我该怎么做?
谢谢.
dog*_*ane 30
您不能直接使用重定向(>),find -exec因为它在命令运行之前发生并创建一个名为的文件{}.为了解决这个问题,你需要在新的shell中使用它sh -c.
另请注意,您无需cat /dev/null > file为了破坏文件.你可以简单地使用> file.
试试这个:
find . -type f -exec sh -c '>"{}"' \;
Run Code Online (Sandbox Code Playgroud)