(LINUX)使用echo和grep删除多个文件

问题描述 投票:0回答:1

我当前目录中有 4 个文件:'#cos#'、ab.txt、cos~、file.txt。我想删除其中包含单词“cos”的所有文件,这也恰好是唯一包含字母“c”、“o”和“s”的单词。我设置了以下内容:

echo * | grep -E '[cos]' | <idk what to put here>

在 中,我应该输入什么才能删除命令输入的所有文件?

linux shell grep delete-file
1个回答
0
投票

实现目标的最简单方法是使用

find
命令:

# find <path> -name "*cos*" -exec rm {} \;
© www.soinside.com 2019 - 2024. All rights reserved.