LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 04-29-2004, 03:01 AM   #1
jayachristina
LQ Newbie
 
Registered: Apr 2004
Posts: 2

Rep: Reputation: 0
Exclamation Tar files in a dir modified before 7 days in a shell script


How could I tar the files (*.csv files) in a directory which are 7 days old?
I need to do this for archiving purposes.
Can you please help out?

Thanks,
Jaya
 
Old 04-29-2004, 03:37 AM   #2
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 57
Try:
Code:
find . -ctime -7 -type f -name "*.csv"
This will list the files with .csv extension that have been created during the last seven days.

Edited addition: If you want to use the above to tar them up you could use something like this:
Code:
tar cfz `date +%Y-week%V`.tar.gz `find . -ctime -7 -type f -name "*.csv"`
(note the backticks for command substitution)This will create a compressed tar file with the csv files created during the last 7 days, and the filename will be YYYY-weekN.tar.gz (currently it would be 2004-week18.tar.gz). Try man date for more options on formatting date output.

Håkan

Last edited by hw-tph; 04-29-2004 at 03:45 AM.
 
Old 04-29-2004, 04:14 AM   #3
jayachristina
LQ Newbie
 
Registered: Apr 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Håkan.
This is exactly what I wanted
But in 'tar cfz ', the z seems to be an invalid option!
tar: z: unknown option
But I can always compress this file again, so that would not be a problem
Thanks again
Jaya
 
Old 05-13-2004, 06:37 AM   #4
Arkane
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
Hello!

Is it possible to use tar to extract a list of files stored in a file or stdinput?

I 've got a dir with lots of tar files.. and want to choose some with grep.

Thanks

Tobias
 
Old 05-14-2004, 02:49 AM   #5
Arkane
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
Hi again and sorry for answering my own question... i 've found a solution this morning...
Since i didn't get it with tar -T i searched a little around and tried xargs

ls |grep "tar.gz" |xargs -n1 tar -xzf

and my problem was gone

I love the pipe!
Tobias
 
  


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
shell scripting: checking for modified files topcat Linux - General 4 12-08-2004 04:43 AM
rename script all files in dir Longinus Linux - Newbie 8 08-02-2004 12:24 AM
help with a script that deletes files more than X days old BrianK Linux - General 5 06-14-2004 09:05 PM
un tar all files in dir Longinus Linux - Newbie 6 03-18-2004 12:33 AM
Bash script (untar *.tar files and then cd to the untared dir) k0ljat Linux - Newbie 2 12-30-2003 05:57 AM


All times are GMT -5. The time now is 11:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration