LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Make tar of most recent directories (https://www.linuxquestions.org/questions/linux-newbie-8/make-tar-of-most-recent-directories-196531/)

drlaz 06-22-2004 04:36 PM

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:
Code:


                      d1

          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.

Tinkster 06-22-2004 06:38 PM

Code:

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 ;)


Cheers,
Tink


All times are GMT -5. The time now is 02:45 PM.