如何在Linux上的Bash中一次删除多个文件? [英] How to delete multiple files at once in Bash on Linux?

查看:241
本文介绍了如何在Linux上的Bash中一次删除多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux服务器上有以下文件列表:

I have this list of files on a Linux server:

abc.log.2012-03-14
abc.log.2012-03-27
abc.log.2012-03-28
abc.log.2012-03-29
abc.log.2012-03-30
abc.log.2012-04-02
abc.log.2012-04-04
abc.log.2012-04-05
abc.log.2012-04-09
abc.log.2012-04-10

我一直在使用命令rm -rf一次删除一个选定的日志文件:

I've been deleting selected log files one by one, using the command rm -rf see below:

rm -rf abc.log.2012-03-14
rm -rf abc.log.2012-03-27
rm -rf abc.log.2012-03-28

还有另一种方法,以便我可以一次删除选定的文件吗?

Is there another way, so that I can delete the selected files at once?

推荐答案

Bash支持各种通配符和扩展名.

Bash supports all sorts of wildcards and expansions.

您的确切案例将由括号扩展,就像这样:

Your exact case would be handled by brace expansion, like so:

$ rm -rf abc.log.2012-03-{14,27,28}

以上内容将扩展为具有所有三个参数的单个命令,等效于键入:

The above would expand to a single command with all three arguments, and be equivalent to typing:

$ rm -rf abc.log.2012-03-14 abc.log.2012-03-27 abc.log.2012-03-28

重要的是要注意,此扩展是在甚至加载rm之前由外壳完成的.

It's important to note that this expansion is done by the shell, before rm is even loaded.

这篇关于如何在Linux上的Bash中一次删除多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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