How to delete many 0 byte files in linux?

前端 未结 10 1986
孤街浪徒
孤街浪徒 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:42

    "...sometimes that does not even delete these files" makes me think this might be something you do regularly. If so, this Perl script will remove any zero-byte regular files in your current directory. It avoids rm altogether by using a system call (unlink), and is quite fast.

    #!/usr/bin/env perl
    use warnings;
    use strict;
    
    my @files = glob "* .*";
    for (@files) {
        next unless -e and -f;
        unlink if -z;
    }
    

提交回复
热议问题