Tag Info

Hot answers tagged

10

use the --directory option from man tar : -C,- -directory DIR change to directory DIR i.e.: tar -C /mnt/sdb1/ -czf /mnt/sdb1/old_files/new.tar.gz myfile.csv


8

This is because files use up space in whole-block increments. So if your block size is 512 bytes and you have a small 100 byte file, the size it actually uses up will be rounded up to the nearest block - in this case 512. When tarring, because the result is a single file, that inefficiency is reduced since there is only one resultant file - the .tar file. ...


5

The z option tells tar to decompress an archive using gunzip (or its internal equivalent), and is appropriate only for gzip-compressed archives, typically with a .tar.gz extension. To decompress archives using other compression formats, you can try tar xvf file to see if your tar is clever enough to figure things out on its own. If it isn't, you can ...


4

Not easily. tar records not only file contents, but also file metadata (name, timestamps, permissions, owner and such). That information has to come from somewhere, and it won't be there in a pipe. You could gzip your database dumps to a file (probably named for the database in question), append the file to a tar archive and then delete the file before ...


3

As Christopher suggested, archivemount can achieve this. Permits writing of files and when unmounted, the .tar.gz file is automatically updated to reflect the changes. # ls -lh download.tar.gz -rw-rw-r--. 1 steve steve 3.1M Feb 16 2010 download.tar.gz # archivemount download.tar.gz /mnt # cd /mnt # find . -ls|head 1 3127 drwxr-xr-x 0 root root ...


3

They went to whatever was your current directory when you ran tar; if you haven't closed the terminal or changed directories since, pwd will tell you where they are.


3

You have first to cd /mnt/sdb1, then launch the tar command. FYI, you don't need to use tarhere as its purpose is to agglomerate several files in a tarball. Since you have only one file here, just use gzip.


3

tar doesn't take the name of the tar file as an argument. The name of the tar file can be passed as an argument to the -f option. You can write tar -x -f P.tgz or (tar has some weird option parsing for historical reasons) tar xf P.tgz or (if tar doesn't see the name of the tar file, you need to tell it explicitly that it's compressed) tar xz <P.tgz ...


2

I cobbled together some python to do what you want. It uses python's tarfile library to append stdin to a tar file, and then simply seeks back in the tar to rewrite the header with the right size at eof. The usage would be: rm -f mytar for db in $dbs do mysqldump ... $db | gzip -c | tarappend -t mytar -f mysql-backup-$db.gz done tar tvf mytar Here's ...


2

With GNU or FreeBSD tar, you can apply a transformation to file names when adding them to an archive (or extracting them). tar czf foo.tgz --transform='!^bar/!!' bar/ foo Portably, you can do the same thing with pax. pax -w -pe -s'!^bar/!!' foo bar/


2

You would need to be at the directory from which the tar file was created, for instance $HOME. Then if you had a tgz of your Documents directory located safely in /backup/Documents.tgz you would do this: $ for file in $(tar -tzf /backup/Documents.tgz); do \ [[ -f $file ]] && rm $file || echo "$file does not exist"; done If you want to also ...


1

In man xz, you'll find that -9 requires 674 MiB of memory for compression (and that it's only useful if you're compressing files bigger than 32 MiB). Try adding about this much swap to provide enough virtual memory for the operation (assuming you're using all your current memory for other purposes).


1

If your version of tar uses xz for --lzma (which is likely, even Debian 6 used that), you can use the XZ_OPT variable: XZ_OPT=-9 tar --lzma ...


1

You can search the filesystem for one of those paths, for example (it can take a while): find / -path "*/jdk1.7.0_79/jre/Welcome.html" The output could be: /path/to/unpacked/tarball/jdk1.7.0_79/jre/Welcome.html The place would then be /path/to/unpacked/tarball/


1

Yes, thanks to FUSE, which allows filesystems to be implemented by userland programs. There are many FUSE filesystems out there, implementing files stored as something other than sectors on a disk, including alternate views of existing filesystems, files on a remote machine, files in an archive, etc. You can use archivemount to mount a specific archive to a ...


1

The following bash one-liner will do approximately what you describe, putting each directory into its own tarball. for d in dir/*/; do { tar -cj "$d" > "${d%/}.tar.bz2" ; } & done ; while [ "$(jobs)" ] ; do fg &>/dev/null ; done ; echo done


1

tar -cj --newer-mtime 2015-07-07 directory | tar -tj | less works If -N is used, tar works on files whose data modification or status change times are newer than the date given. While --newer-mtime only checks mtime and disregards ctime


1

Use the -C option to tar: -C Directory Causes the tar command to perform a chdir subroutine to the directory specified by the Directory variable.


1

You can use the find command to select files based on their modification time. cd /path/to/directory find -type f -newermt 2007-01-01 ! -newermt 2008-01-01 Note that this selects files created in 2007 in your time zone, and files timestamped exactly at midnight on year change are grouped with the preceding year. If your version of CentOS has an old ...


1

No, and I miss that feature so much: my question on Ask Ubuntu. If the file to be archived is a raw file with no filesystem metadata associated to it, tar doesn't have neither a filename nor a path necessary to build the internal directories / files tree (to say the least). I think that something can be done in Perl, which has some library dedicated to ...


1

Of course you can. Firstly tar in most cases does not include compression, it hands that off to a helper (if it supports it at all). At first that helper was compress (.tar.Z). I have also seen gzip (.tar.gz or .tgz), bzip2 (.tar.bz2), infozip's zip and unzip tools (.tar.zip), and some I cant rember the official names for (.tar.lha, .tar.lhz, .tar.zoo, ...



Only top voted, non community-wiki answers of a minimum length are eligible