1

I want to find and delete log file on linux Terminal.

Usually I use this

find -name '*.log'

after the File found, next use this script

find -name '*.log' -type f -delete

that script work for

filename.log

but now I want to find and delete file like this

mysqld.log-20180208  mysqld.log-20180223  mysqld.log-20180310  mysqld.log-20180325  mysqld.log-20180409
mysqld.log-20180123.xz  mysqld.log-20180209  mysqld.log-20180224  mysqld.log-20180311  mysqld.log-20180326  mysqld.log-20180410
mysqld.log-20180124.xz  mysqld.log-20180210  mysqld.log-20180225  mysqld.log-20180312  mysqld.log-20180327  mysqld.log-20180411
mysqld.log-20180125.xz  mysqld.log-20180211  mysqld.log-20180226  mysqld.log-20180313

How Can I find filename.log-12313

I want delete filename.log- with number only.

Can anyone fix this?

thanks.

Im very appreciate your answer.

0

You already use globs; you can use them for any part of the file name:

find -name '*.log*' -type f -delete

Or if you want to be more specific:

find \( -name '*.log' -o -name '*.log-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' -o -name '*.log-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].xz' \) -type f -delete
2
  • can it use except, exemple: except filename.log, – Uchsun Apr 20 '18 at 6:25
  • Yeah, there'll be questions about that here or at unix.SE. – l0b0 Apr 20 '18 at 8:12

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.