How to delete multiple files at once in Bash on Linux?

前端 未结 7 761
有刺的猬
有刺的猬 2021-01-29 19:09

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
ab         


        
7条回答
  •  逝去的感伤
    2021-01-29 19:30

    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
    

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

提交回复
热议问题