Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 am trying to get list of files modified between particular period of time as explain in this answer.

I stored date and time in two variables [nn and nn1 (stupid naming)] and tried with find command. I got following error -

vikram@vikram-Studio-XPS-1645:~$ echo $nn1
10-04-12 23:26:48
vikram@vikram-Studio-XPS-1645:~$ echo $nn
10-05-12 00:26:48
vikram@vikram-Studio-XPS-1645:~$ find . -newermt $nn -and -not -newermt $nn1 -print
find: paths must precede expression: 00:26:48
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

Why this error occur ??

share|improve this question
What you need is double quotes around "$nn" and "$nn1". Note that files modified at "$nn1" are included, but those modified at "$nn" are not (probably makes no difference here, but if you're using -newer somefile it does). – drevicko Jun 16 '13 at 23:44
using the above answer I couldnt get the files with in the time range(YYYYMMDDHHmmss). Instead it is displaying all the files in the specified path. Could any one please let me know how to list the files with in the timestamp range. – user4809060 Apr 21 '15 at 4:42
up vote 11 down vote accepted

Your syntax is slightly off. Let's redo this with meaningful variable names; we'll understand better what's happening as we go along.

export newerthan="2012-10-04 00:05:00"
export olderthan="2012-10-05 16:30:00"
find . -newermt "$newerthan" ! -newermt "$olderthan"

This will first find files and directories modified after October 4th, 2012, at 12:05 AM. Then, it will remove results that were modified after October 5th, 2012, at 4:30 PM.

To get results without the leading ./ on every line, use this command:

find . -newermt "$newerthan" ! -newermt "$olderthan" | sed 's/^.\///g'
share|improve this answer
Sorry. Silly question. – Vikram Oct 4 '12 at 20:09
Not at all! There's no such thing :) – SirCharlo Oct 4 '12 at 20:09
Why do you need to export your variables if all your use of them is to substitute into a command? – Ruslan Jun 2 at 18:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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