I have a dir with:
- bla-bla-bla1.tar.7z
- bla-bla-bla2.tar.7z
- bla-bla-bla3.tar.7z
- _bla-bla-bla_foo.tar.7z
I need to find and delete all files ".7z" except "_.7z"
I use find /backups/ -name "*.7z" -type f -mtime +180 -delete
How i can do it?
I have a dir with:
I need to find and delete all files ".7z" except "_.7z"
I use find /backups/ -name "*.7z" -type f -mtime +180 -delete
How i can do it?
It should be
Another approach is to use an additional, negated primary with
find
:The simple regex in the other answers is better for your use case, but this demonstrates a more general approach using the
!
operator available tofind
.A quick way given you have bash 4.2.25, is to simply use bash pattern matching to remove all .7z, but the ones having _.7z, like this:
In regular expressions, the
^
operator means "any character except for". Thus[^_]
means "any character except for _". E.g.:So, if your intention is to exclude files starting with
_
, your full command line would be:If you'd like to exclude any occerance of
_
, you can use theand
andnot
operators offind
, like: