On the command line, 'find' reports back an illegal time value
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?
01 Answer
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:
- "echo " (contained in the first set of 1 marks)
- "-1308741881 | bc" (contained in the second set of 1 marks)
- 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 -dateAnd 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)sAnd for csh:
set now=`date +%s-1308741881`; set date=`echo $now | bc`s; find . -mtime -$dateAnd possibly for other shells (untested):
NOW=`date +%s-1308741881`; DATE=`echo $NOW | bc`; find . -mtime -${DATE}sP.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.
5