How to delete many 0 byte files in linux?

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

    Here is an example, trying it yourself will help this to make sense:

    bash-2.05b$ touch empty1 empty2 empty3
    bash-2.05b$ cat > fileWithData1
    Data Here
    bash-2.05b$ ls -l
    total 0
    -rw-rw-r--    1 user group           0 Jul  1 12:51 empty1
    -rw-rw-r--    1 user group           0 Jul  1 12:51 empty2
    -rw-rw-r--    1 user group           0 Jul  1 12:51 empty3
    -rw-rw-r--    1 user group          10 Jul  1 12:51 fileWithData1
    bash-2.05b$ find . -size 0 -exec rm {} \;
    bash-2.05b$ ls -l
    total 0
    -rw-rw-r--    1 user group          10 Jul  1 12:51 fileWithData1
    

    If you have a look at the man page for find (type man find), you will see an array of powerful options for this command.

提交回复
热议问题