Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find files in mmyyyy and/or mmyy format

Status
Not open for further replies.

confuseddddd

Programmer
May 22, 2003
53
US
Is doing a grep to locate files in a directory where the file name contains either in mmyyyy or mmyy format, the best way to locate the files???? And if so, any suggestions on how to accomplish this???

We need to every other month, clean up files and sometimes the file names are in mmyyyy format and sometimes the file names are in mmyy format.

Thanks in advance for any assistance.
 
Assuming that each mmyyyy file has a modification time of mmyyyy as well, then you could look at using these two commands
Code:
touch -t yyyymmdd0000 /tmp/stamp$$
find /path ! -newer /tmp/stamp$$ -print
rm /tmp/stamp$$

When you're sure that it works, change the find to be
Code:
touch -t yyyymmdd0000 /tmp/stamp$$
find /path ! -newer /tmp/stamp$$ -exec rm -f {} \;
rm /tmp/stamp$$

Essentially, you create a temporary file using the touch command, which has a modification date of your cut-off point.
The find command finds all files which are then older (or not newer as the command goes) than that reference file.

The find command has a whole set of options to further refine the search if need be.

/path is just wherever your files are - change to suit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top