There is a list of folders:

2014-12-17 2014-12-21 2014-12-22 2014-12-23 2015-01-13 2015-01-14 2015-01-15 2015-01-16 2015-01-17 

How to delete all folders and their contents, which names begin with "2014"? Thank.

  • 2
    rm 2014* -rf , but only carefully - KoVadim
  • what does it mean "neat"?) - Jenkamen
  • well, you can add one space and get problems. rm 2014 * -rf - will remove a bit more. - KoVadim 4:21 pm
  • @mee when typing the command rm -rf что_нибудь should always be at least 2 times to think what this command will delete before clicking <Enter>. - andy.37
  • one
    If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

as written in man bash , the EXPANSION section, the Pathname Expansion subsection , the Pattern Matching subtitle, the * character can be used instead of any number of characters when referring to files / directories.

in the appendix to your question, “mask” 2014* will “select” only those files / directories whose name contains 2014 and then any number of characters :

 $ ls -d 2014* 2014-12-17 2014-12-21 2014-12-22 2014-12-23 

and to delete (non-empty) directories, use the command rm -r имя-каталога :

 $ rm -r 2014* 
  • rm -r 2014 * rm: go down to the catalog "2014-12-17"? So writes. - Jenkamen
  • @mee, is it happening in the ubuntu distribution? there, as far as I know, rm is a pseudonym ( alias ) for rm -i (see in man rm what this means) - “taking care of the user so as not to hurt himself”. To avoid using an alias at startup, you can add a backslash before rm : \rm -r 2014* . - aleksandr barakin