Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
1  
If you included a description of exactly what forfiles.exe does, those of us who know Linux very well will find helping you much easier. –  MikeyB Sep 18 '09 at 21:01
    
sorry, It's my bad not to explain what forfiles.exe does in windows; but a simple google search gives satisfying results on what forfiles.exe does. Anyway, I'm still ashamed of myself why "find" didn't come to my mind before asking this silly questions ;) –  Serdar Dalgic Sep 18 '09 at 21:26
    
@MikeyB, you could have followed the link to the other question. There was a forefiles description there. I updated the question to include a link directly to the technet docs. –  Zoredache Sep 18 '09 at 21:46

4 Answers 4

I think find provides the functionality that forfiles offers.

share|improve this answer
    
Ah yes, thanks for reminding ;) I searched google a little bit and I think this should be the answer: howtogeek.com/howto/ubuntu/… –  Serdar Dalgic Sep 18 '09 at 20:41

find is the full-powered replacement, but for simple operations on files in the current directory this sh-script can be pretty useful (and easier to read/write) as well:

for file in *.jpg; do
  echo "do something with $file"
done
share|improve this answer
    
You could have spelled it "for files" ;-) [I know, then it wouldn't make sense.] –  Dennis Williamson Sep 18 '09 at 22:22

You can create a cron job that uses find with the appropriate arguments, e.g. -mtime +7

share|improve this answer
3  
What does cron have to do with forfiles? –  Bill Weiss Sep 18 '09 at 20:47

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 -iname instead 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 -maxdepth parameter with 1.
  • /c -> -exec. Also replace @file with {} and don't forget to end the command with \; (many beginners are bit by this error)
  • /d -> -mtime n. File's data was last modified n*24 hours ago.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.