Find the answer to your Linux question:
Results 1 to 6 of 6
Hello Friends, I have started getting into unix recently and seek your help in sorting out one of my porblems related to TAR files. I have a tar file which ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    8

    Issue in Listing Files in a TAR

    Hello Friends,

    I have started getting into unix recently and seek your help in sorting out one of my porblems related to TAR files.

    I have a tar file which contains 10 files in it. My objective is to read the file names in the tar files (along with their directory path) and pass the list of files to a java program. I have completed the implementation but found some issue is in the order of the file names that the "tar -tvf" command outputs.

    My program logic works this way: (i) I trigger a shell script on receipt of a new tar file. (ii) Do a tar - tvf to get the list of files in the tar file and pass that list to a java class.

    issue: "tar -tvf" does not list the files in the tar file based on the creation timestamp and it lists the file names in random order. Is there any way to list the file names in tar based on creation timestamp ?

    Thanks,
    Bala.

  2. #2
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    717
    Hello,

    two things that come to mind:
    * ask your man-pages for more information about the commands and options that your version tar includes
    * sort the random output

    Greetings,
    D.

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Location
    Zagreb, Croatia
    Posts
    9
    Code:
    tar -tvf file.tar | sort -k 4,5

  4. #4
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    The order that files are listed is not random. It is the order in which they are stored in the file, which is the order in which they are given as arguments when tar created the tarball. The tar file format is not very complex, and there are several sites online that describe it.
    --- rod.
    Stuff happens. Then stays happened.

  5. #5
    Just Joined!
    Join Date
    Jul 2010
    Posts
    8
    Thanks Bokica for your valuable inputs.

    I am able to get things right and sort files based on timestamp from your hint. But still there is a scenario where i am getting things wrong to understand the issue better.

    A user places several files in a directory - say 3 a.txt,b.txt,c.txt sequentially one after another in the directory. Then he tars the directory and sends it to me. Now i need to list the files in the tar in the order they were placed in the directory (i.e, by create timestamp) and pass the list to another program. The command "tar -tvf file.tar | sort -k 4,5
    " works when the file creation timestamp differs atleast by a second. But when the user places 2 files in the same second (say 2 files created on 10th second of a 15th minute), the above command does not sort the file based on the order when the file was created as both the files will be having the same create timestamp.

    If we are to have the millisecond information in the file creation timestamp then the sort command may sort the list to accuracy. But is there any way to get this ?

    Example:

    -rw-r--r-- sam/dba 4151 2010-07-17 10:46:14 testdir/IN/FILE10191.dat
    -rw-r--r-- sam/dba 4151 2010-07-17 10:46:14 testdir/IN/FILE1019.dat

    In the above case I created the file FILE1019.dat and immediately created the file FILE10191.dat. But when sorted, the order is still in reverse. This is the issue and want to get fixed.

    Thanks,
    Bala.

  6. #6
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    Wikipedia lists the granularity of ext3 filesytem datestamps as one second, so the filesystem is not likely to help you with your sorting problem. Is there any possibility to create the files with a datestamp as part of the filename? This would remove all ambiguity.
    --- rod.
    Stuff happens. Then stays happened.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...