The Computer Oracle

How to delete files on the command line with regular expressions?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping

--

Chapters
00:00 How To Delete Files On The Command Line With Regular Expressions?
00:52 Accepted Answer Score 33
01:10 Answer 2 Score 6
01:18 Answer 3 Score 13
01:32 Thank you

--

Full question
https://superuser.com/questions/138282/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #bash #shell #regex #zsh

#avk47



ACCEPTED ANSWER

Score 33


In bash you can use:

rm FOO1{3..5}

or

rm FOO1{3,4,5}

to delete FOO13, FOO14 and FOO15.

Bash expansions brace are documented here.




ANSWER 2

Score 13


For future readers, the find command can also delete files. I settled on this for a similar problem:

find . -type f -regex '...' -delete

but the chosen answer is the simplest anser to this question.




ANSWER 3

Score 6


ls | grep regex | xargs rm