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

前端 未结 4 983
眼角桃花
眼角桃花 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:51

    With GNU's find you can use the -delete action:

    find dir -type f -delete
    

    With standard find you can use -exec rm:

    find dir -type f -exec rm {} +
    

提交回复
热议问题