Please - Looking for a online command to delete files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please - Looking for a online command to delete files
# 1  
Old 07-19-2017
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.

Code:
$ 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

Moderator's Comments:
Mod Comment
Please use code tags

Last edited by rbatte1; 07-20-2017 at 07:27 AM.. Reason: Removed colour and replaced with ICODE tags.
# 2  
Old 07-19-2017
Code:
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
Code:
find .   mtime +2 -type f  \( -name '*.LOG' -a ! -name S0000000.LOG \)  | grep 'S0000000.LOG'

You should not see S0000000.LOG in the output.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 07-19-2017
Wow.. Thanks. It works as expected Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to bypass rm command when there are no files to delete?

Hi, Below command works fine when we have other files apart from hello.txtls | ggrep -v hello* | xargs rm -rfBut, if there is only one file i.e hello.txt the rm command does not find anything to delete and the script hangs. While there could be trivial ways to check using if conditions if... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Command to delete a word in all files

can anyone tell me what is the commands to delete the below particular word in the all files located in one particular file path files/ll>grep "/ftp/" test.kell ftp -m uskmc -d /ftp/ -i filename.zip output should be : ftp -m uskmc -d -i filename.zip (4 Replies)
Discussion started by: ramkumar15
4 Replies

3. Shell Programming and Scripting

Command to delete half of files in directory.

Hello Friends, I have directory called /tmp. which stores the log files. Whenever it becomes full, i want to delete half of files from all log files. even after deleting the files, if space is more than 90% then it should delete rest of half files. While deleting files, older files... (7 Replies)
Discussion started by: Nakul_sh
7 Replies

4. Shell Programming and Scripting

Find command to delete the files

Hi All, I've created 2 files touch -t 201309101234 aa10 touch -t 201309111234 aa11 Exact 60 days before from today date is SEPT 12th . As per the following command as i gave +60 means the files which were created before sept12th should be deleted find /etc/logs/*aa* -type f -atime +60... (5 Replies)
Discussion started by: smile689
5 Replies

5. UNIX for Dummies Questions & Answers

Find command to delete old files

Hi, I want to delete all the log files that was created on year 2008. My command is not working. Any idea? find . -name '*.log' -mtime 1460 -exec ls -lt {} \; Thank you. (2 Replies)
Discussion started by: samnyc
2 Replies

6. Shell Programming and Scripting

Delete empty files from a directory entered in command prompt

My code to "Delete empty files from a directory entered in command promt" #/bin/sh echo "Enter directory" read gh for file in `ls $gh` do # to get the size of file a=$( ls -l file | awk ' {print $7} '); echo $a if then echo "removing file " rm file fi done (6 Replies)
Discussion started by: adirajup
6 Replies

7. Solaris

Need to know command to delete more than 3 million files from /var/spool/clientmqueue

Hi I need to delete more than 3 million files from /var/spool/clientmqueue. When I give the following command to delete the files, I get the error # pwd /var/spool/clientmqueue # rm -f * /usr/bin/rm: arg list too long Please tell me how can I delete the files (5 Replies)
Discussion started by: sb200
5 Replies

8. Shell Programming and Scripting

Need a command to delete all files apart from last file generated

Hi, I have a directory named (/output). this directory has files in the below format abc.* , xyz*, djj*, iwe*, weewe*, rier*, 3948903ddfgf* these files are generated at random. what i need to do is. delete all the files of all kinds but keep only the last generated file of... (5 Replies)
Discussion started by: dazdseg
5 Replies

9. Solaris

Could not able to delete the files through find command need expert advice

Hi Gurus I am facing a problem, there is a folder called /a where there are lots of files which are occupying space anything between 30 GB to 100 GB as I am not able to check the space occupied by that folder through "du -sh /a" command as I don't see any output after more than 1 hour of... (4 Replies)
Discussion started by: amity
4 Replies

10. Solaris

How to delete Directory and inside files using Find command

I am using the following Command to delete Directory with contents. But this command is deleting inside files only not directories. is there any change need in my command? find -type f -mtime +3 -exec rm -r {} \; Thanks (3 Replies)
Discussion started by: bmkreddy
3 Replies
Login or Register to Ask a Question