Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 10 down vote accepted
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.

share|improve this answer
+1 only cause @slhch changed $() notation instead of superseded backticks :P Why it is so important? – confiq Mar 1 '12 at 14:05
@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
Gotch. Thanks @slhck. – qweet Mar 1 '12 at 15:20
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .