Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-22-2004, 05:36 PM   #1
LQ Newbie
Registered: Jan 2004
Location: SF Bay Area, CA
Distribution: Fedora 10 and 11; Snow Leopard :-)
Posts: 18

Rep: Reputation: 0
Unhappy Make tar of most recent directories

I have a tree of directories, and I would like to archive the most recent directory at the last level (i.e, of the directories that don't contain subdirectories). Alternatively, I can rm the older directories and tar what's left. Maybe a picture would help:


           d2                    d3

     d4        d5        d6          d7
I want to archive whichever of d4 or d5 is more recent, and whichever of d6 and d7 is more recent. I don't care about d2 vs d3 or d4 vs d7.

I assumed some brilliant pattern to find would do this, but if so it is far beyond my newbie skills.
Old 06-22-2004, 07:38 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913Reputation: 913
 tar cvzf new_dir.tar.gz `find -type d -mindepth 3 -maxdepth 3 -exec ls -ld --time-style=long-iso {} \; | sort -g -k 6,7 | tail -n 1 | awk '{print $8}'`

It's a bit of a mouthfull but should work ;)



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
Tar won't exclude directories. yougene Slackware 9 12-01-2005 10:32 AM
Getting access to directories when extracting TAR djpalm64 Mandriva 2 01-28-2005 11:32 AM
tar, excluding directories recursively towlie Linux - Newbie 3 06-17-2004 01:32 PM
Tar including all parent directories? everythingand2 Linux - General 4 12-14-2003 07:31 PM
tar multiple directories computera Linux - General 2 11-17-2001 08:27 AM > Forums > Linux Forums > Linux - Newbie

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

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