13

I have a folder which has many files. Some of the data files are labelled 1, 2, 3, ..., 300

I want to remove these data files using the terminal. How do I do this?

I want to do something like

rm some-regular-expression-giving-numbers-from-0--300
2
  • Are they just called 1, 2, etc. and do they all match an expression that gives numbers from 0 to 300, or are there any other elements in the filename? Can you give us a more concrete example, maybe with a directory listing?
    – slhck
    Jul 15 '12 at 18:23
  • Yes they are just called 1, 2, etc. Jul 15 '12 at 18:39
17

You can try

rm some-files-with-numbers{0..300}

This will delete:

some-files-with-numbers0

some-files-with-numbers1

some-files-with-numbers2

...

some-files-with-numbers300
0
1

I like superuser’s answer, but to add another possibility:

find . -regex './some-files-with-numbers[123]?[0-9]?[0-9]' -delete
2
  • 1
    What about some-files-with-numbers301?
    – cYrus
    Jul 15 '12 at 18:50
  • @cYrus I am aware of the limitations :) My answer was more aimed at being an alternative to superuser’s one.
    – qdii
    Jul 15 '12 at 20:43

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.