linux – 删除文本文件中列出的文件

前端之家收集整理的这篇文章主要介绍了linux – 删除文本文件中列出的文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个文件导出了一堆需要删除文件名.我需要知道如何删除每个文件而不必在命令行一次发出一个文件.

我已经考虑过在for循环中把它括起来,这可能会起作用,但是想知道是否有一个更简单,甚至更好的解决方案来做到这一点.

谢谢.

解决方法

rm -rf `cat /path/to/filename`

“字符可以用$()替换

来自bash手册页:

Command Substitution
       Command substitution allows the output of a command to replace the command
       name.  There are two forms:

              $(command)
       or
              `command`

       Bash performs the expansion by executing command and replacing the command
       substitution  with  the  standard output of the command,with any trailing
       newlines deleted.  Embedded newlines are not  deleted,but  they  may  be
       removed  during  word splitting.  The command substitution $(cat file) can
       be replaced by the equivalent but faster $(< file).

       When the old-style backquote  form  of  substitution  is  used,backslash
       retains its literal meaning except when followed by $,`,or \.  The first
       backquote not preceded by a backslash terminates the command substitution.
       When  using  the  $(command)  form,all characters between the parentheses
       make up the command; none are treated specially.

       Command substitutions may be nested.  To nest when  using  the  backquoted
       form,escape the inner backquotes with backslashes.

       If the substitution appears within double quotes,word splitting and path‐
       name expansion are not performed on the results.
原文链接:https://www.f2er.com/linux/399285.html

猜你在找的Linux相关文章