unix从文件中清除内容而不删除任何目录

unix从文件中清除内容而不删除任何目录,unix,Unix,我有一个目录“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

我有一个目录“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 
使用
查找(1)

  • 使用
    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
    

    @HenkLangeveld,编号列表(编号后没有内容)适用于缩进代码块。“我往后退了。”亨克兰杰尔德,谢谢你的评论。我在回答中添加了你的评论。我的浏览器(chrome、linux)一定有问题,因为我看不到预期效果。我只是在单独的行中看到每个列表索引和项目。@HenkLangeveld,(Windows7,Chrome)。在chromium和linux中也有类似的显示。这正是我所看到的。不是编号列表通常呈现的方式。我只是喜欢编号的列表布局,但这不是什么大问题。
    find Adir -type f | while read path; do echo 0 > $path; done
    
    find Adir -type f | while read path; do > $path; done