You are not logged in.

#1 2009-12-27 12:33:54

YZMSQ
Member
From: Hangzhou,Zhejiang,China
Registered: 2009-11-18
Posts: 97

(solved)An easy question for you but not me...

Hi there
I don't know what's wrong with this:      find . -atime +3 | tar -czvf tarfile.tar.gz
PS: I want to write a simple script to find the files which haven't been visited for 3 days and compress them. 
Never laugh at me.....I'm just a beginner to learn shell.:/

Last edited by YZMSQ (2009-12-28 13:14:37)


This is the way the world ends
Not with a bang but a whimper
                            -------T·S·Eliot

Offline

#2 2009-12-27 13:07:37

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: (solved)An easy question for you but not me...

tar can read filenames from a file with -T where - will be stdin. So
find . -type f -atime +3 | tar cfz tar.tgz -T -

Note that find will print . without -type f or -mindepth 1, which would add everything at least once.

Offline

#3 2009-12-27 13:24:39

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: (solved)An easy question for you but not me...

Another possibility is to use the xargs command to build a parameter string from stdin.

find . -name something | xargs tar -cf allsomethings.tar

Last edited by tlvb (2009-12-27 17:07:16)


I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

#4 2009-12-27 13:36:10

YZMSQ
Member
From: Hangzhou,Zhejiang,China
Registered: 2009-11-18
Posts: 97

Re: (solved)An easy question for you but not me...

Thank you very much for your help!!! big_smile


This is the way the world ends
Not with a bang but a whimper
                            -------T·S·Eliot

Offline

#5 2009-12-28 09:07:47

YZMSQ
Member
From: Hangzhou,Zhejiang,China
Registered: 2009-11-18
Posts: 97

Re: (solved)An easy question for you but not me...

But what's wrong with this command line: find . -atime +3 -ok tar -czvf tarfile.tar.gz {} \;
I need your help,please.


This is the way the world ends
Not with a bang but a whimper
                            -------T·S·Eliot

Offline

#6 2009-12-28 13:00:16

PirateJonno
Forum Fellow
From: New Zealand
Registered: 2009-04-13
Posts: 372

Re: (solved)An easy question for you but not me...

YZMSQ wrote:

But what's wrong with this command line: find . -atime +3 -ok tar -czvf tarfile.tar.gz {} \;
I need your help,please.

with that, tar -czvf will be executed lots of times, once for every file that matches the criteria. what you want is either a list of files to tar with one command, or to add individual files to an existing archive


"You can watch for your administrator to install the latest kernel with watch uname -r" - From the watch man page

Offline

#7 2009-12-28 13:11:33

YZMSQ
Member
From: Hangzhou,Zhejiang,China
Registered: 2009-11-18
Posts: 97

Re: (solved)An easy question for you but not me...

thank you for your help!


This is the way the world ends
Not with a bang but a whimper
                            -------T·S·Eliot

Offline

Board footer

Powered by FluxBB