Sponsored Content
Full Discussion: Delete Old files from Tar
Top Forums UNIX for Beginners Questions & Answers Delete Old files from Tar Post 303045282 by shekar7 on Sunday 15th of March 2020 09:09:33 AM
Old 03-15-2020
Quote:
Originally Posted by vbe
What have you tried so far?

Sorry "Vbe" I Could Have Mentioned My code , I am Getting Result as Expected.

But I Want to Know Without Extracting files to tmp directory, find out files older than n days.

As You Mentioned, I tried to use gzcat it is not working, But zcat is Working and it is displaying the file content, I don't Want that.
Code:
         gunzip file.Tar.gz
         tar -xvf  file.Tar  -C tmp
         find  tmp -name "*.txt" -mtime +7 -printf '%f\n' > Indelte;
         tar -vf file.Tar --delete -T Indelte;


Last edited by shekar7; 03-15-2020 at 10:50 AM.. Reason: spelling mistake
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

delete a file from an existing Solaris tar

How can I delete a file from an existing Solaris tar file ? (not gtar) (2 Replies)
Discussion started by: avnerht
2 Replies

2. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies

3. Linux

tar usage and delete/create username

dear Linux expert, I am using Fedora R5 how to use tar to archive /var to a test_var.tar and compressing it? how to delete a user? just remove the line in /etc/passwd? and then what is the procedure to create a new user ? many thank (2 Replies)
Discussion started by: zp523444
2 Replies

4. Shell Programming and Scripting

Delete a file from XXX.tar.Z

Hi All can u please let me know how to delete a file from XXX.tar.Z file with out uncompressing this file. thanks in advance. --Bali (0 Replies)
Discussion started by: balireddy_77
0 Replies

5. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

6. Solaris

option to delete .tar file while extracting

Is there an option in tar which deletes the .tar file as soon as it is successfully extracted. (5 Replies)
Discussion started by: vickylife
5 Replies

7. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

8. UNIX for Dummies Questions & Answers

How to delete original files after using a tar operation.

I have a list of log files in a directory. Once i tar them I need to remove the original log files. How do i do it? (4 Replies)
Discussion started by: manutd
4 Replies

9. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

10. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies
Archive::Tar::Wrapper(3pm)				User Contributed Perl Documentation				Archive::Tar::Wrapper(3pm)

NAME
Archive::Tar::Wrapper - API wrapper around the 'tar' utility SYNOPSIS
use Archive::Tar::Wrapper; my $arch = Archive::Tar::Wrapper->new(); # Open a tarball, expand it into a temporary directory $arch->read("archive.tgz"); # Iterate over all entries in the archive $arch->list_reset(); # Reset Iterator # Iterate through archive while(my $entry = $arch->list_next()) { my($tar_path, $phys_path) = @$entry; print "$tar_path "; } # Get a huge list with all entries for my $entry (@{$arch->list_all()}) { my($tar_path, $real_path) = @$entry; print "Tarpath: $tar_path Tempfile: $real_path "; } # Add a new entry $arch->add($logic_path, $file_or_stringref); # Remove an entry $arch->remove($logic_path); # Find the physical location of a temporary file my($tmp_path) = $arch->locate($tar_path); # Create a tarball $arch->write($tarfile, $compress); DESCRIPTION
Archive::Tar::Wrapper is an API wrapper around the 'tar' command line utility. It never stores anything in memory, but works on temporary directory structures on disk instead. It provides a mapping between the logical paths in the tarball and the 'real' files in the temporary directory on disk. It differs from Archive::Tar in two ways: o Archive::Tar::Wrapper doesn't hold anything in memory. Everything is stored on disk. o Archive::Tar::Wrapper is 100% compliant with the platform's "tar" utility, because it uses it internally. METHODS
my $arch = Archive::Tar::Wrapper->new() Constructor for the tar wrapper class. Finds the "tar" executable by searching "PATH" and returning the first hit. In case you want to use a different tar executable, you can specify it as a parameter: my $arch = Archive::Tar::Wrapper->new(tar => '/path/to/tar'); Since "Archive::Tar::Wrapper" creates temporary directories to store tar data, the location of the temporary directory can be specified: my $arch = Archive::Tar::Wrapper->new(tmpdir => '/path/to/tmpdir'); Tremendous performance increases can be achieved if the temporary directory is located on a ram disk. Check the "Using RAM Disks" section below for details. Additional options can be passed to the "tar" command by using the "tar_read_options" and "tar_write_options" parameters. Example: my $arch = Archive::Tar::Wrapper->new( tar_read_options => "p" ); will use "tar xfp archive.tgz" to extract the tarball instead of just "tar xf archive.tgz". Gnu tar supports even more options, these can be passed in via my $arch = Archive::Tar::Wrapper->new( tar_gnu_read_options => ["--numeric-owner"], ); By default, the "list_*()" functions will return only file entries. Directories will be suppressed. To have "list_*()" return directories as well, use my $arch = Archive::Tar::Wrapper->new( dirs => 1 ); If more files are added to a tarball than the command line can handle, "Archive::Tar::Wrapper" will switch from using the command tar cfv tarfile file1 file2 file3 ... to tar cfv tarfile -T filelist where "filelist" is a file containing all file to be added. The default for this switch is 512, but it can be changed by setting the parameter "max_cmd_line_args": my $arch = Archive::Tar::Wrapper->new( max_cmd_line_args => 1024 ); $arch->read("archive.tgz") "read()" opens the given tarball, expands it into a temporary directory and returns 1 on success und "undef" on failure. The temporary directory holding the tar data gets cleaned up when $arch goes out of scope. "read" handles both compressed and uncompressed files. To find out if a file is compressed or uncompressed, it tries to guess by extension, then by checking the first couple of bytes in the tarfile. If only a limited number of files is needed from a tarball, they can be specified after the tarball name: $arch->read("archive.tgz", "path/file.dat", "path/sub/another.txt"); The file names are passed unmodified to the "tar" command, make sure that the file paths match exactly what's in the tarball, otherwise "read()" will fail. $arch->list_reset() Resets the list iterator. To be used before the first call to $arch-list_next()>. my($tar_path, $phys_path, $type) = $arch->list_next() Returns the next item in the tarfile. It returns a list of three scalars: the relative path of the item in the tarfile, the physical path to the unpacked file or directory on disk, and the type of the entry (f=file, d=directory, l=symlink). Note that by default, Archive::Tar::Wrapper won't display directories, unless the "dirs" parameter is set when running the constructor. my $items = $arch->list_all() Returns a reference to a (possibly huge) array of items in the tarfile. Each item is a reference to an array, containing two elements: the relative path of the item in the tarfile and the physical path to the unpacked file or directory on disk. To iterate over the list, the following construct can be used: # Get a huge list with all entries for my $entry (@{$arch->list_all()}) { my($tar_path, $real_path) = @$entry; print "Tarpath: $tar_path Tempfile: $real_path "; } If the list of items in the tarfile is big, use "list_reset()" and "list_next()" instead of "list_all". $arch->add($logic_path, $file_or_stringref, [$options]) Add a new file to the tarball. $logic_path is the virtual path of the file within the tarball. $file_or_stringref is either a scalar, in which case it holds the physical path of a file on disk to be transferred (i.e. copied) to the tarball. Or it is a reference to a scalar, in which case its content is interpreted to be the data of the file. If no additional parameters are given, permissions and user/group id settings of a file to be added are copied. If you want different settings, specify them in the options hash: $arch->add($logic_path, $stringref, { perm => 0755, uid => 123, gid => 10 }); If $file_or_stringref is a reference to a Unicode string, the "binmode" option has to be set to make sure the string gets written as proper UTF-8 into the tarfile: $arch->add($logic_path, $stringref, { binmode => ":utf8" }); $arch->remove($logic_path) Removes a file from the tarball. $logic_path is the virtual path of the file within the tarball. $arch->locate($logic_path) Finds the physical location of a file, specified by $logic_path, which is the virtual path of the file within the tarball. Returns a path to the temporary file "Archive::Tar::Wrapper" created to manipulate the tarball on disk. $arch->write($tarfile, $compress) Write out the tarball by tarring up all temporary files and directories and store it in $tarfile on disk. If $compress holds a true value, compression is used. $arch->tardir() Return the directory the tarball was unpacked in. This is sometimes useful to play dirty tricks on "Archive::Tar::Wrapper" by mass- manipulating unpacked files before wrapping them back up into the tarball. $arch->is_gnu() Checks if the tar executable is a GNU tar by running 'tar --version' and parsing the output for "GNU". Using RAM Disks On Linux, it's quite easy to create a RAM disk and achieve tremendous speedups while untarring or modifying a tarball. You can either create the RAM disk by hand by running # mkdir -p /mnt/myramdisk # mount -t tmpfs -o size=20m tmpfs /mnt/myramdisk and then feeding the ramdisk as a temporary directory to Archive::Tar::Wrapper, like my $tar = Archive::Tar::Wrapper->new( tmpdir => '/mnt/myramdisk' ); or using Archive::Tar::Wrapper's built-in option 'ramdisk': my $tar = Archive::Tar::Wrapper->new( ramdisk => { type => 'tmpfs', size => '20m', # 20 MB }, ); Only drawback with the latter option is that creating the RAM disk needs to be performed as root, which often isn't desirable for security reasons. For this reason, Archive::Tar::Wrapper offers a utility functions that mounts the ramdisk and returns the temporary directory it's located in: # Create new ramdisk (as root): my $tmpdir = Archive::Tar::Wrapper->ramdisk_mount( type => 'tmpfs', size => '20m', # 20 MB ); # Delete a ramdisk (as root): Archive::Tar::Wrapper->ramdisk_unmount(); Optionally, the "ramdisk_mount()" command accepts a "tmpdir" parameter pointing to a temporary directory for the ramdisk if you wish to set it yourself instead of letting Archive::Tar::Wrapper create it automatically. KNOWN LIMITATIONS
o Currently, only "tar" programs supporting the "z" option (for compressing/decompressing) are supported. Future version will use "gzip" alternatively. o Currently, you can't add empty directories to a tarball directly. You could add a temporary file within a directory, and then "remove()" the file. o If you delete a file, the empty directories it was located in stay in the tarball. You could try to "locate()" them and delete them. This will be fixed, though. o Filenames containing newlines are causing problems with the list iterators. To be fixed. BUGS
Archive::Tar::Wrapper doesn't currently handle filenames with embedded newlines. LEGALESE
Copyright 2005 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
2005, Mike Schilli <cpan@perlmeister.com> perl v5.14.2 2012-03-21 Archive::Tar::Wrapper(3pm)
All times are GMT -4. The time now is 08:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy