LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-31-2010, 11:36 AM   #1
clcbluemont
Member
 
Registered: Feb 2009
Distribution: Slackware
Posts: 110
Blog Entries: 3

Rep: Reputation: 15
Unhappy 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.
 
Old 05-31-2010, 12:07 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by clcbluemont View Post
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.

Last edited by colucix; 05-31-2010 at 12:08 PM.
 
1 members found this post helpful.
Old 05-31-2010, 12:40 PM   #3
clcbluemont
Member
 
Registered: Feb 2009
Distribution: Slackware
Posts: 110
Blog Entries: 3

Original Poster
Rep: Reputation: 15
Talking 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find all files modified in a date range riteshanand40 Linux - Newbie 2 04-30-2010 05:12 AM
Zipping files by a date range nixusr Linux - Newbie 3 06-10-2008 01:14 PM
find out the files created on a particular date. ZAMO Linux - General 3 02-08-2008 02:38 AM
deleting by date a specific range of files nooks12 Linux - Newbie 2 01-08-2008 03:45 PM
How to find the date for all the files in a directory Uday123 AIX 6 02-23-2006 09:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration