LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-01-2013, 03:49 AM   #1
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Rep: Reputation: Disabled
Script to list the contents of the latest archive?


Hi,

I am looking to write a script that will:

Get the latest Archive from a list
List the contents of the tar.gz
Print the name, size, and date of modification

I have:

Code:
gunzip -c ~/backups/PROJECTNAME_2013-02-28-16:27:27.tar.gz | tar -tvf -
Which gives me:

r--r-- ubuntu/ubuntu 5 2013-02-19 03:15 file0
-rw-r--r-- ubuntu/ubuntu 0 2013-02-28 16:47 fil1
-rwxr-xr-x ubuntu/ubuntu 795 2013-02-19 01:51 fil2
-rwxr-xr-x ubuntu/ubuntu 643 2011-11-20 14:13 fil3

But I want to sort this by last modification date:

Code:
gunzip -c ~/backups/PROJECTNAME_2013-02-28-16:27:27.tar.gz | tar -tvf - | sort -n
gives me:

-rw-r--r-- ubuntu/ubuntu 0 2013-02-28 16:47 fil1
-rw-r--r-- ubuntu/ubuntu 5 2013-02-19 03:15 fil0
-rwxr-xr-x ubuntu/ubuntu 643 2011-11-20 14:13 fil3
-rwxr-xr-x ubuntu/ubuntu 795 2013-02-19 01:51 fil2

Any ideas? to get order right:

name, size, and date of modification
 
Old 03-01-2013, 04:24 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
You have to specify the field to be sorted out, using the -k option:
Code:
sort -k4n
Moreover, using GNU tar you don't need to uncompress the archive. Therefore you will end up with something like this:
Code:
tar tvf ~/backups/PROJECTNAME_2013-02-28-16:27:27.tar.gz | sort -k4n | cut -d' ' -f6-,3,4
Hope this helps.
 
Old 03-01-2013, 08:23 AM   #3
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
You have to specify the field to be sorted out, using the -k option:
Code:
sort -k4n
Moreover, using GNU tar you don't need to uncompress the archive. Therefore you will end up with something like this:
Code:
tar tvf ~/backups/PROJECTNAME_2013-02-28-16:27:27.tar.gz | sort -k4n | cut -d' ' -f6-,3,4
Hope this helps.
Excellent, thanks very much, gerat help.
 
  


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
how to list the contents of CD? elthox Linux - Newbie 5 05-07-2008 09:07 AM
Apache FancyIndex listing widgets to view archive contents acid_kewpie Linux - Software 0 07-04-2006 03:20 AM
list contents of directory without listing contents baddah Linux - Newbie 2 06-12-2006 04:02 AM
search mailing list archive lordofring Linux - Software 3 03-12-2006 10:56 AM
get list of latest list of packages bobwall Linux - Distributions 1 11-30-2004 03:48 PM


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