加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-13 17:04:29 所属栏目:Linux 来源:网络整理
导读:我有一个文件导出了一堆需要删除的文件名.我需要知道如何删除每个文件而不必在命令行一次发出一个文件. 我已经考虑过在for循环中把它括起来,这可能会起作用,但是想知道是否有一个更简单,甚至更好的解决方案来做到这一点. 谢谢. 解决方法 rm -rf `cat /path/t
我有一个文件导出了一堆需要删除的文件名.我需要知道如何删除每个文件而不必在命令行一次发出一个文件.

我已经考虑过在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                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读