ls: terminated by signal 13 when using xargs

后端 未结 3 760
梦谈多话
梦谈多话 2020-12-20 10:38

I\'m using the following command to delete four largest size files in a folder:

find \"/var/www/site1/\" -maxdepth 1 -type f | xargs ls -1S | head -n 4 | xar         


        
3条回答
  •  感动是毒
    2020-12-20 11:36

    You are purposely terminating your program with head -n 4, which creates the broken pipe because you terminated it before the "caller" finished. Since this is expected by you, you can ignore the error by redirecting it to /dev/null which discards it:

    find "/var/www/site1/" -maxdepth 1 -type f | xargs ls -1S | head -n 4 | xargs -d '\n' rm -f 2>/dev/null

提交回复
热议问题