How to find files except given name?

前端 未结 4 1387
-上瘾入骨i
-上瘾入骨i 2021-02-13 01:50

There is a directory containing the following files:

.
├── bla-bla-bla1.tar.7z
├── bla-bla-bla2.tar.7z
├── bla-bla-bla3.tar.7z
└── _bla-bla-bla_foo.tar.7z
         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-13 02:08

    Another approach is to use an additional, negated primary with find:

     find /backups/ -name "*.7z"  ! -name '_.7z' -type f -mtime +180 -delete
    

    The simple regex in the other answers is better for your use case, but this demonstrates a more general approach using the ! operator available to find.

提交回复
热议问题