Shell命令/脚本删除名称在文本文件中的文件 [英] Shell command/script to delete files whose names are in a text file

查看:78
本文介绍了Shell命令/脚本删除名称在文本文件中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.txt文件中有一个文件列表(例如list.txt)。我想删除该列表中的文件。我以前没有做脚本。能否提供我可以使用的Shell脚本/命令。我有bash外壳。

解决方案

 而读取-r文件名;做
rm $ filename
完成< list.txt

  rm $(< list.txt)


将会失败。



我认为应该可以:

  xargs -a list.txt -d'\n'rm 


I have a list of files in a .txt file (say list.txt). I want to delete the files in that list. I haven't done scripting before. Could some give the shell script/command I can use. I have bash shell.

解决方案

while read -r filename; do
  rm "$filename"
done <list.txt

is slow.

rm $(<list.txt)

will fail if there are too many arguments.

I think it should work:

xargs -a list.txt -d'\n' rm

这篇关于Shell命令/脚本删除名称在文本文件中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆