2

I would like to delete folders with specified regex, but I could not build a good regex.

I have:

/root
  /my-picture-2015
    /my-picture-2015-1
    /my-picture-2015-2
  /my-picture-2015-1
  /my-picture-2015-2
  /my-picture-2015-3
etc.

Directory my-picture-2015 is a backup which I would like restored. It could stay in this directory, but I have to delete all my-picture-2015-X only from root directory. Directories in my-picture-2015 have to stay.

2 Answers 2

2

If you are inside the root directory, then you can use this command to delete the required folders:

find -type d -maxdepth 1 -iregex ".*my-picture-[0-9]*-[0-9]" -exec rm -r {} +

Here,

-maxdepth   ==>   do no descend beyond the first level for searching
0
1

Simply:

rm -rf /root/my-picture-2015-*/
1
  • and it will not remove : /root/my-pictures-2015/my-pictures-2015-1 ? Jul 10, 2015 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .