System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

question about file manipulation

navin
Super Advisor

question about file manipulation

Hi
I have to remove files older than certain date within the dir - the files are look like the below format.Can you please suggest a string to do that.
filename.web.pc.com-err_log.xxxxx
Thanks
Learning ...
1 REPLY
James R. Ferguson
Acclaimed Contributor

Re: question about file manipulation

Hi:

Why not simply do:

# touch -m CCYYMMDDhhmm /tmp/myref
# cd /path
# find . -type f ! -newer /tmp/myref -exec rm {} +

Substitute whatever date (e.g. 201009010001) for the "CCYYMMDDhhmm" string.

The 'find()' will return files that are *not* newer (more recent) than the reference point (file) created. Hence these files are *old* and are the ones you want to remove.

If you need to, you can *and* the match of the filename to the pattern you seek, like:

# find . -type f ! -newer /tmp/myref -name "*pc.comm-err_log*" -exec rm {} +

For testing purposes, change the 'rm {}' to 'echo {}' until you are satisfied that you will find what you want.

Regards!

...JRF...