Results 1 to 5 of 5
Hi,
I am attempting to search through a series of directories for directories older than two weeks, then remove all files with the extension .jpg from those older directories. The ...
- 03-25-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 3
Unexpected result from using find command with rm
Hi,
I am attempting to search through a series of directories for directories older than two weeks, then remove all files with the extension .jpg from those older directories. The jpg files have an incorrect create/modify date because they are images pulled from a webcam with a bad date/time/time zone, so I cannot check the date of the individual files. The command i've tried is:
find -type d -mtime +14 -exec rm -f '{}/*.jpg' \;
Instead of deleting the jpg files inside of the subdirectories I get no output and the files still exist. I believe it is not interpreting the *.jpg part and matching all the jpg files, instead trying to delete a file named '*.jpg'. Any suggestions appreciated!
TIA.
- 03-25-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 25
looks like you havent specified the location to find in your command. try this
find (filesystem) -type f -mtime +14 -name "*.jpg" -exec rm -f {} \;
or you can also use the xargs funtion to delete the file
- 03-25-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 3
Thanks for the suggestion... The problem is that I can't check the date on the individual files with -type f... The jpgs are pulled from a webcam and the cam has had a messed up date/time or time zone for the past three years apparently so the only correct creation/modify date is on the folder containing the jpgs.
Unfortunately, I can't just delete the directory containing the jpgs either because there are time lapse movies composed of the jpgs in the same dir that need to stay around.
- 03-25-2009 #4Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
The problem is that the '*' in the find command isn't being treated as a glob. It's looking for a file that has a asterisk in the filename. To get what you want you have to use find twice and pipe the filenames to xargs as follows:
Code:find (filesystem) -type d -mtime +14 -exec find {} -type f -name "*.jpg" -maxdepth 1 \; | xargs rm -fv
- 03-25-2009 #5Just Joined!
- Join Date
- Mar 2009
- Posts
- 3


Reply With Quote
