【问题标题】:delete all but 10 newest files linux but I am facing No such file or directory exception删除除 10 个最新文件 linux 之外的所有文件,但我面临没有此类文件或目录异常
【发布时间】:2017-11-17 15:26:58
【问题描述】:

我在 sudo 正确的用户时使用以下命令;

ls -t1 /cs/wlsconfig/wls10.3.2/servers/cmt/logs | tail -n +10 | xargs rm -r

但我在使用此命令时遇到以下异常;

rm: cannot remove `cmt.log00045': No such file or directory

不管运行以下命令是否返回带有文件列表的结果;

ls -t1 /cs/wlsconfig/wls10.3.2/servers/cmt/logs | tail -n +10

任何线索将不胜感激!

【问题讨论】:

    标签: linux


    【解决方案1】:

    您需要在rm 调用之前添加路径或先更改目录。试试这个:

    cd /cs/wlsconfig/wls10.3.2/servers/cmt/logs
    ls -t1 | tail -n +10 | xargs rm -r
    

    但是,这不适用于包含空格的文件名。这就是为什么它是bad idea to parse the output of ls 的原因之一。

    看看这些类似的问题及其解决方案:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      相关资源
      最近更新 更多