Unix: How to delete files listed in a file

后端 未结 13 1642
遥遥无期
遥遥无期 2020-12-04 06:31

I have a long text file with list of file masks I want to delete

Example:

/tmp/aaa.jpg
/var/www1/*
/var/www/qwerty.php

I need delet

13条回答
  •  一向
    一向 (楼主)
    2020-12-04 07:19

    You could use '\n' for define the new line character as delimiter.

    xargs -d '\n' rm < 1.txt
    

    Be careful with the -rf because it can delete what you don't want to if the 1.txt contains paths with spaces. That's why the new line delimiter a bit safer.

    On BSD systems, you could use -0 option to use new line characters as delimiter like this:

    xargs -0 rm < 1.txt
    

提交回复
热议问题