Find: Invalid predicate when using -newermt

I use the find command to retrieve files between a specific time and tar with the following command:

find /lag/cnn -max-depth 3 -newermt "2013-12-19 00:00" -o -type f -newermt "2013-12-16 00:00" -print0 | xargs -0 tar acf out.tar.gz 

but when I run this command, I get: find: invalid predicate `-newermt '. what is the problem? and how can I get around this.

UPDATE: What I'm actually trying to do is path (using ls -lrt / lag / cnn / * / *):

  /lag/cnn/Example1/one/a.tar.gz /lag/cnn/Example1/two/a.tar.gz /lag/cnn/Example1/three/a.tar.gz /lag/cnn/Example2/one/a.tar.gz 

I use grep for example1 and got the list in sample.txt as follows:

  /lag/cnn/Example1/one/a.tar.gz /lag/cnn/Example1/two/a.tar.gz /lag/cnn/Example1/three/a.tar.gz 

from this sample.txt I want tar files based on time.since touch does not work with the file. I chose find command.thing, I have to do this from the root directory.

  touch /lag/cnn/*/* start -d "2013-12-19 00:00" 

will not work for sure. So, is there a way to read files between a specific time and tar, or use this touch to use -newer and find files between a specific time.

+7
linux command
source share
2 answers

Your version of find does not support the -newermt predicate, so you cannot use it. As a workaround, you can use the -newer predicate. This predicate needs the file as a reference: instead of the date of absolute modification, it will use the date the file was modified. To do this, you can create the appropriate "marker files", for example:

 touch /tmp/mark.start -d "2013-12-19 00:00" touch /tmp/mark.end -d "2013-12-16 00:00" 

Then -newer using the -newer predicate:

 find /some/path -newer /tmp/mark.start 

Btw it looks like your conditions were wrong: you have -newermt twice with different dates, which in your example will receive all files newer than the older date, ignoring the newer date. Perhaps you wanted to do something like this:

 find /some/path -newer /tmp/mark.start ! -newer /tmp/mark.end 

Finally, your tar will not work if the argument list is too long and xargs is split into several executions, because all executions recreate the tar file. You should use the -T tar flag instead of xargs :

 find /some/path -print0 | tar acf out.tar.gz --null -T- 
+8
source share

Find files newer than "start" and older than "end"

 touch /tmp/mark.start -d "2016-02-16 00:00" touch a -d "2016-02-15 00:01" touch b -d "2016-02-16 00:01" touch c -d "2016-02-17 00:00" touch d -d "2016-02-18 00:00" touch e -d "2016-02-19 00:01" touch /tmp/mark.end -d "2016-02-19 00:00" 

Command: find . -type f -newer /tmp/mark.start ! -newer /tmp/mark.end find . -type f -newer /tmp/mark.start ! -newer /tmp/mark.end

==================================================== ========================

Output:

 -bash-3.2$ find . -type f -newer /tmp/mark.start ! -newer /tmp/mark.end ./d ./b ./c -bash-3.2$ 
+1
source share

All Articles