0

I want to delete all files that have two numbers and a dot in beginning of their names
for example:

01. abc
02. xyz
6
rm [0-9][0-9].*

will do it for files in the current directory (no quotes — you want to match files). The . doesn't need to be escaped, because this is a shell glob and not a regular expression (if it were a regex, that would be a wildcard).

If you are looking to do this recursively, find is probably your best bet.

7

Recursively :

find . -type f -name '[0-9][0-9].*' -delete

require GNU find, or :

find . -type f -name '[0-9][0-9].*' -exec rm {} \;
  • 1
    If it's just files in the current dir, simply rm '[0-9][0-9].*' – glenn jackman Dec 13 '14 at 20:15
  • 3
    @glennjackman Yes but no quotes in that case. – mattdm Dec 13 '14 at 20:16
  • whats different between two – Edward Torvalds Dec 13 '14 at 20:20
  • @edwardtorvalds, in quotes, it's a literal string. Without quotes, it will expand to match filenames. – glenn jackman Dec 13 '14 at 20:24
  • 1
    Ack. I didn't see sputnick changing his answer. Alright: -exec rm {} \; has to spawn an new process for rm for each file found. -delete is built-in to find, so it will be more efficient. – glenn jackman Dec 13 '14 at 20:30
-1

Delete the files recursively with '-r' option

rm -rf name_pattern*    
eg : rm -rf dept*
  • 1
    This doesn't really answer the question, since it's about matching file names beginning with any two digits followed by a period. The question didn't mention anything about files being in subdirectories either, so not sure why mention the recursive option. – filbranden May 4 '18 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.