Please - Looking for a online command to delete files

I have list of files like below, I want to delete files older than 2 days except S0000000.LOG, I have command find /export/home/X_GZPQJK/out/file* -mtime +1 -exec rm {} \; but it is deleting S0000000.LOG, Can you please help me how to modify command to delete except S0000000.LOG.

$ ls -ltr
total 0
-rw-r--r-- 1 mqm mqm 0 Jul 12 00:00 S0000005.LOG
-rw-r--r-- 1 mqm mqm 0 Jul 13 00:00 S0000006.LOG
-rw-r--r-- 1 mqm mqm 0 Jul 14 00:00 S0000003.LOG
-rw-r--r-- 1 mqm mqm 0 Jul 14 00:00 S0000000.LOG
-rw-r--r-- 1 mqm mqm 0 Jul 15 00:00 S0000003.LOG
-rw-r--r-- 1 mqm mqm 0 Jul 17 00:00 S0000002.LOG
-rw-r--r-- 1 mqm mqm 0 Jul 18 00:00 S0000001.LOG
$pwd
/home/mqm
find .   mtime +2 -type f  \( -name '*.LOG' -a ! -name S0000000.LOG \) -exec rm {};

Assuming I got what you want try this. Just do not run the exec part until you are sure it does what you want.

In other words do something like this

find .   mtime +2 -type f  \( -name '*.LOG' -a ! -name S0000000.LOG \)  | grep 'S0000000.LOG' 

You should not see S0000000.LOG in the output.

1 Like

Wow.. Thanks. It works as expected :slight_smile: