LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-28-2009, 07:15 AM   #1
rsiazon
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Rep: Reputation: 0
Cool selectively tar based on date just the innermost directories of a single directory


I need help to selectively archive the subdirectories of a single parent directory in which said subdirectories have creation year-date 2008 and older. Thanks a lot.
 
Old 07-28-2009, 07:27 AM   #2
zQUEz
Member
 
Registered: Jun 2007
Distribution: Fedora, RHEL, Centos
Posts: 294

Rep: Reputation: 54
You could locate the directories by using a find command such as:
Code:
find / -type d -mtime +365
and then pipe that into a tar command. Also adjust 365 to however many days since 2008.
 
Old 07-28-2009, 07:56 AM   #3
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,387
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
I should first note that unix file systems do not have creation times. Instead, there are access, modify, and change times.

To archive everything in directory 'example' that has not been modified since the start of 2009:
Code:
touch -d "1 Jan 2009" date-mark
tar cf subset.tar `find example -maxdepth 1 \! -newer date-mark`
The '-maxdepth' parameter prevents the 'find' command from recursing through the subdirectories, and the '\! -newer' looks for anything with a modification date older than the date-mark file. And those are backquotes around the find command.

Last edited by neonsignal; 07-28-2009 at 08:00 AM.
 
Old 07-28-2009, 09:55 AM   #4
rsiazon
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Guys...here's the situation...parent /school1 has subdirectories say /stud1,/stud2,/stud3 etcetera....parent /school2 has subdirs /stud1,/stud2/stud3 etcetera....same with parents /school3../school4 etcetera....I need to archive via tar only subdirs /stud(n) which have not been modified since 2008 and earlier...excluding the parents...sorry I'm a newbie..I'm not sure if I am stating the problem properly and clearly...thanks a lot...
 
Old 07-28-2009, 11:22 AM   #5
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,387
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
So assuming the current directory is the one that contains school1, school2 etc:

Code:
touch -d "1 Jan 2009" date-mark
tar cf oldstudents.tar `find school* -maxdepth 1 \! -newer date-mark`
This creates a tar archive file of all the students who have not been modified in 2009.

Last edited by neonsignal; 07-28-2009 at 11:25 AM.
 
Old 07-29-2009, 01:15 AM   #6
rsiazon
LQ Newbie
 
Registered: Jul 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Got it..! Maraming salamat sa tulong niyo! (Filipino for "THANKS A LOT FOR YOUR HELP!") ...God bless

Tex Siazon
 
  


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
Copying a single file into each directory of a directory tree mlapl1 Linux - Newbie 2 06-27-2007 11:18 PM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 09:43 AM
Script to move directories based on first letter to a new directory of that letter tworkemon Linux - Newbie 8 01-30-2007 08:18 PM
tar - extracting a single directory from a large archive? lowpro2k3 Linux - General 1 07-24-2005 03:44 AM
How do I decompress and desarchive multiple .tar.gz files to a single directory? Baldorg Linux - Software 7 11-27-2003 01:42 PM


All times are GMT -5. The time now is 01:57 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