How to delete many 0 byte files in linux?

前端 未结 10 1985
孤街浪徒
孤街浪徒 2020-12-07 11:19

I\'ve a directory with many number of 0 byte files in it. I can\'t even see the files when I use the ls command. I\'m using a small script to delete these files but sometime

相关标签:
10条回答
  • 2020-12-07 11:55

    With GNU's find (see comments), there is no need to use xargs :

    find -name 'file*' -size 0 -delete
    
    0 讨论(0)
  • 2020-12-07 11:57

    If you want to find and remove all 0-byte files in a folder:

    find /path/to/folder -size 0 -delete
    
    0 讨论(0)
  • 2020-12-07 11:58

    Use find combined with xargs.

    find . -name 'file*' -size 0 -print0 | xargs -0 rm
    

    You avoid to start rm for every file.

    0 讨论(0)
  • 2020-12-07 11:58
    find . -maxdepth 1 -type f -size 0 -delete
    

    This finds the files with size 0 in the current directory, without going into sub-directories, and deletes them.

    To list the files without removing them:

    find . -maxdepth 1 -type f -size 0
    
    0 讨论(0)
提交回复
热议问题