Unix: How to delete files listed in a file

后端 未结 13 1556
遥遥无期
遥遥无期 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:21

    In case somebody prefers sed and removing without wildcard expansion:

    sed -e "s/^\(.*\)$/rm -f -- \'\1\'/" deletelist.txt | /bin/sh
    

    Reminder: use absolute pathnames in the file or make sure you are in the right directory.

    And for completeness the same with awk:

    awk '{printf "rm -f -- '\''%s'\''\n",$1}' deletelist.txt | /bin/sh
    

    Wildcard expansion will work if the single quotes are remove, but this is dangerous in case the filename contains spaces. This would need to add quotes around the wildcards.

    0 讨论(0)
提交回复
热议问题