LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   find files in date range (https://www.linuxquestions.org/questions/linux-newbie-8/find-files-in-date-range-811292/)

clcbluemont 05-31-2010 10:36 AM

find files in date range
 
ls -l /tmp/empty_file*
-rw-r--r-- 1 root root 0 2010-05-30 08:00 /tmp/empty_file
-rw-r--r-- 1 root root 0 2010-05-30 12:00 /tmp/empty_file1

This looks good, the files expected to be seen are output:
find /usr \( -newer /tmp/empty_file -a \! -newer /tmp/empty_file1 \) -print

But this shows me files that should not be output and likewise when I replace ls with tar it is tarring a whole bunch of stuff I do not want:
find /usr \( -newer /tmp/empty_file -a \! -newer /tmp/empty_file1 \) -exec ls -l {} \;


In the end I would like to replace the "ls" with "tar cvvfp some.tar {} \;", but can't figure out what is going wrong here.

colucix 05-31-2010 11:07 AM

Quote:

Originally Posted by clcbluemont (Post 3987483)
find /usr \( -newer /tmp/empty_file -a \! -newer /tmp/empty_file1 \) -print

But this shows me files that should not be output

The search criteria should be fine. What stuff do you see as unwanted output?

In any case you may want to limit the results to files and exclude directories, otherwise the tar command will archive the entire content of the directories (despite the timestamp of the files inside).

Moreover, take in mind that -exec executes the command multiple times, each one over each line of input (that is over each object found). Typically the tar command is used over a bunch of files all together, hence better to pipe the output to xargs, like in
Code:

find /usr -type f \( -newer /tmp/empty_file -a \! -newer /tmp/empty_file1 \) -print0 | xargs -0 tar cvvpf some.tar
In cases where -type f does not appear in the search refinement, you might add --no-recursion to the tar options to avoid directories archived twice.

clcbluemont 05-31-2010 11:40 AM

Solved: find files in date range
 
Thank You, you nailed what exec was doing "tar command will archive the entire content of the directories". The following is working for me:

find /usr \( -newer /tmp/empty_file -a \! -newer /tmp/empty_file1 \) -type f |xargs tar cvf new.tar


All times are GMT -5. The time now is 07:47 PM.