HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
Showing results for 
Search instead for 
Did you mean: 

question about file manipulation

Super Advisor

question about file manipulation

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.
Learning ...
James R. Ferguson
Acclaimed Contributor

Re: question about file manipulation


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.