3

I edit a bunch of txt files with the line

vim *.txt

but what I'd really like to do is edit all the files that haven't been modified in the last day (or n days, or n hours) - what's the most command-line-fu way of doing this?

10
vim $(find * -type f -mtime 0)

$() is a command substitution. Allows for some magic to be done (in this case, providing a list of files for you to edit). You can read more about them here

Inside the command substitution we're going to do a find command that looks for anything in the current directory (*) that is a file (-type f) and was modified today (mtime 0).

mtime looks for files that were modified in n*24. So if mtime was equal to 1, if would look for files modified yesterday. You could also use mmin to look for files that were modified n minutes ago.

vim $(find * -type f -mmin $[n * 1])

In this case, replace n with minute. You could even go and swap whatever you want in that arithmetic expansion to suit your needs.

  • +1 only cause @slhch changed $() notation instead of superseded backticks :P Why it is so important? – confiq Mar 1 '12 at 14:05
  • 2
    @confiq It's not that important but 1) easier to read 2) harder to make nesting errors 3) considered standard now – slhck Mar 1 '12 at 14:43
  • 1
    Absolutely great answer that solved my problem - just some minor feedback - vim $(find *.txt -type f '!' -mtime 0) was what actually solved the problem (because I wanted txt files only and there was a 'not' in the question) but I'm putting this in only for completeness. Thanks again... – Joe Mar 7 '12 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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