我有一个目录“ADir”,包含递归的一些目录。
我可以运行什么unix命令来确保
1) directories are not deleted AND
2) NO file is deleted
3) all the files currently present contain only one data and that is 0
以及
的命令1) directories are not deleted AND
2) NO file is deleted
3) all the files currently present are emptied out
答案 0 :(得分:2)
使用find(1)
:
echo 0 > {}
:( {}
替换为匹配的文件路径)
find ADir -type f -exec sh -c "echo 0 > {}" \;
> {}
:
find ADir -type f -exec sh -c "> {}" \;
<强>更新强>
对于大量文件,请使用单个shell实例:
find Adir -type f | while read path; do echo 0 > $path; done
find Adir -type f | while read path; do > $path; done