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 want to run the following command.

find . -mtime -60s

When I do, I get this output instead:

CLIENT% echo `date +%s`-1308741881 | bc
5152
CLIENT% find . -mtime -`echo `date +%s`-1308741881 | bc`s
-1308741881: Command not found.
find: -mtime: -date: illegal time value
CLIENT%

What's going on here?

share|improve this question

The problem is that ` marks are used to denote commands who's output should be substituted in your command... so your command is actually three commands:

  1. "echo " (contained in the first set of 1 marks)
  2. "-1308741881 | bc" (contained in the second set of 1 marks)
  3. find . -mtime -OUTPUT FROM COMMAND #1date +%sOUTPUT FROM COMMAND #2

Command #1 outputs nothing, and command #2 results in the "Command not found" error, because -1308741881 is not a valid command, then outputs nothing either.

Then finally the third command runs, with those replacements and looks like this:

find . -mtime -date

And since "-date" isn't a valid time, it complains about that, too, saying "illegal time value"

The underlying problem is that you're trying to use nested `` marks, which the shell interprets as two separate commands.

A better way to express what you want is this (for bash):

find . -mtime -$(echo $(date +%s-1308741881) | bc)s

And for csh:

set now=`date +%s-1308741881`; set date=`echo $now | bc`s; find . -mtime -$date

And possibly for other shells (untested):

NOW=`date +%s-1308741881`; DATE=`echo $NOW | bc`; find . -mtime -${DATE}s

P.S. I don't think this does what you expect... your date command is returning a number of seconds, but -mtime expects a number of days as input. I'm guessing you'll probably want to adjust your date command accordingly.

share|improve this answer
    
CLIENT% find . -mtime -$(echo $(date +%s-1308741881 ) | bc )s Illegal variable name. – user87005 Jun 22 '11 at 8:32
    
Which shell are you using? Maybe it doesn't understand $() syntax – Flimzy Jun 22 '11 at 8:35
    
I've updated my answer with another version of the same command that might work better in other shells. Please let me know if it works for you. – Flimzy Jun 22 '11 at 8:37
1  
I am using csh shell. – user87005 Jun 22 '11 at 8:38
    
Okay, I have appended my answer once again, with a command that I have tested to work with csh. However, note that find does not accept 'seconds' as a valid -mtime paramater (at least not with my version of find), so the command still fails in that regard. – Flimzy Jun 22 '11 at 8:46

You must log in to answer this question.

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