sorry if this is asked before but, I was curious about what is the equivalent Linux command of forfiles.exe in Windows? This came to my mind when I saw this question
-
I think find provides the functionality that forfiles offers.
Hailsematary : Ah yes, thanks for reminding ;) I searched google a little bit and I think this should be the answer: http://www.howtogeek.com/howto/ubuntu/delete-files-older-than-x-days-on-linux/From Zoredache -
findis the full-powered replacement, but for simple operations on files in the current directory thissh-script can be pretty useful (and easier to read/write) as well:for file in *.jpg; do echo "do something with $file" doneDennis Williamson : You could have spelled it "for files" ;-) [I know, then it wouldn't make sense.]From Joachim Sauer -
You can create a cron job that uses find with the appropriate arguments, e.g. -mtime +7
Bill Weiss : What does cron have to do with forfiles?From Jason -
The find command does what you want. Here's an example:
find /mnt/Pictures -name '*.jpg' \! -mtime 7 -exec rm {} \;This will delete all the jpg files from
/mnt/Pictures, which haven't been modified in the last 7 days (168 hours). If you don't care about the case of the filenames use-inameinstead of-name.Here's a correspondence between the parameters of forfiles and the parameters of find:
/p-> the path is the first argument of find/s-> by default find searches in all subdirectories. To disable this use the-maxdepthparameter with 1./c->-exec. Also replace@filewith{}and don't forget to end the command with\;(many beginners are bit by this error)/d->-mtime n. File's data was last modifiedn*24 hours ago.
From Cristian Ciupitu
0 comments:
Post a Comment