LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   problem with using find and tar together (https://www.linuxquestions.org/questions/linux-newbie-8/problem-with-using-find-and-tar-together-552317/)

zest n zeal 05-08-2007 12:15 PM

problem with using find and tar together
 
Hi, what I have been trying to do is tar up all the files that were touched in the last 24 hours into a single file. Seems simple right?

sohpsy211:/respaldo # find /home/am0032/ -mtime 0


found all the files as expected... but as soon as I did this ....

sohpsy211:/respaldo # find /home/am0032/ -mtime 0 | tar zcvf /respaldo/today.tgz -T-

Then the input from the find command was ignored and the entire contents of /home/am0032/ starts to get tarred up.

Any ideas why? Or how to get around this?

Many thanks for any assistance.

Adam

Centinul 05-08-2007 01:07 PM

try this:

Code:

find /home/am0032/ -mtime 0 -exec tar zcvf /respaldo/today.tgz  \;
This isn't tested so I'm not sure if it will work.

HTH,

Centinul

Tinkster 05-08-2007 01:25 PM

Hi, and welcome to LQ!

Quote:

Originally Posted by zest n zeal
Hi, what I have been trying to do is tar up all the files that were touched in the last 24 hours into a single file. Seems simple right?

sohpsy211:/respaldo # find /home/am0032/ -mtime 0


found all the files as expected... but as soon as I did this ....

sohpsy211:/respaldo # find /home/am0032/ -mtime 0 | tar zcvf /respaldo/today.tgz -T-

Then the input from the find command was ignored and the entire contents of /home/am0032/ starts to get tarred up.

Any ideas why? Or how to get around this?

Many thanks for any assistance.

Adam

Chances are it is working. But if any file in /home/am0032/
has an mtime of 0, so will /home/am0032; hence it will all
be tarred up. What happens if you add -type f to the find?



Cheers,
Tink

jlliagre 05-08-2007 01:39 PM

Quote:

Originally Posted by zest n zeal
Hi, what I have been trying to do is tar up all the files that were touched in the last 24 hours into a single file. Seems simple right?

sohpsy211:/respaldo # find /home/am0032/ -mtime 0


found all the files as expected...

Not only files but directories too, including the topmost one as you are missing the "-type f" option.
Quote:

but as soon as I did this ....

sohpsy211:/respaldo # find /home/am0032/ -mtime 0 | tar zcvf /respaldo/today.tgz -T-

Then the input from the find command was ignored and the entire contents of /home/am0032/ starts to get tarred up.
The input wasn't ignored.
Quote:

Any ideas why? Or how to get around this?
If there aren't too much files, you can run this:
Code:

tar czvf /respaldo/today.tgz $(find ~am0032 -type f -mtime 0)
For a more robust solution, that one should work:
Code:

find ~am0032 -type f -mtime 0 -print0 | tar czvf /respaldo/today.tgz -T - --null

zest n zeal 05-08-2007 01:47 PM

thanx a lot
 
the type f thing fixed it all :)

Tinkster 05-08-2007 01:53 PM

Glad we're not one of the worlds best Linux support
sites for nothing ;}


Cheers,
Tink


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