Delete all files but keep all directories in a bash script?

前端 未结 4 990
眼角桃花
眼角桃花 2021-01-30 23:31

I\'m trying to do something which is probably very simple, I have a directory structure such as:

dir/
    subdir1/
    subdir2/
        file1
        file2
              


        
4条回答
  •  醉话见心
    2021-01-30 23:46

    find dir -type f -exec rm {} \;
    

    where dir is the top level of where you want to delete files from

    Note that this will only delete regular files, not symlinks, not devices, etc. If you want to delete everything except directories, use

    find dir -not -type d -exec rm {} \;
    

提交回复
热议问题