M HYPE SPLASH
// updates

On the command line, 'find' reports back an illegal time value

By Andrew Adams

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?

0

1 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:

  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.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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