Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 9 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

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.