Unix:如何删除文件中列出的文件 [英] Unix: How to delete files listed in a file
问题描述
我有一个长文本文件,其中包含要删除的文件掩码列表
I have a long text file with list of file masks I want to delete
示例:
/tmp/aaa.jpg
/var/www1/*
/var/www/qwerty.php
我需要删除它们.尝试rm` cat 1.txt`它说列表太长了.
I need delete them. Tried rm `cat 1.txt` and it says the list is too long.
找到了此命令,但是当我从列表中检查文件夹时,其中一些仍然有文件
xargs rm <1.txt
手动rm调用可从此类文件夹中删除文件,因此权限没有问题.
Found this command, but when I check folders from the list, some of them still have files
xargs rm <1.txt
Manual rm call removes files from such folders, so no issue with permissions.
推荐答案
这不是很有效,但是如果您需要全局模式(例如/var/www/*),则可以使用
This is not very efficient, but will work if you need glob patterns (as in /var/www/*)
for f in $(cat 1.txt) ; do
rm "$f"
done
如果您没有任何模式,并且确定文件中的路径不包含空格或其他怪异的东西,则可以使用xargs,如下所示:
If you don't have any patterns and are sure your paths in the file do not contain whitespaces or other weird things, you can use xargs like so:
xargs rm < 1.txt
这篇关于Unix:如何删除文件中列出的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!