Questions tagged [tar]

The tar archive format and/or the command-line utility for working with tar files.

Filter by
Sorted by
Tagged with
376 votes
2 answers
765k views

Compress a folder with tar?

I'm trying to compress a folder (/var/www/) to ~/www_backups/$time.tar where $time is the current date. This is what I have: cd /var/www && sudo tar -czf ~/www_backups $time" I am ...
user avatar
  • 3,901
195 votes
6 answers
349k views

How to extract specific file(s) from tar.gz

How can we extract specific files from a large tar.gz file? I found the process of extracting files from a tar in this question but, when I tried the mentioned command there, I got the error: $ tar --...
user avatar
190 votes
9 answers
359k views

tar: Removing leading `/' from member names

root@server # tar fcz bkup.tar.gz /home/foo/ tar: Removing leading `/' from member names How can I solve this problem and keep the / on file names ?
user avatar
  • 2,001
190 votes
1 answer
297k views

How do you extract a single folder from a large tar.gz archive?

I am using this command on a 5GB archive tar -zxvf archive.tar.gz /folder/in/archive is this the correct way to do this? It seems to be taking forever with no command line output...
user avatar
  • 4,691
185 votes
5 answers
142k views

How to choose directory name during untarring

Say I have file named ugly_name.tar, which when extracted, becomes ugly_name directory. What command can I use such that the resulting directory name is pretty_name instead?
user avatar
  • 61.2k
146 votes
13 answers
150k views

How to XZ a directory with TAR using maximum compression?

So I need to compress a directory with max compression. How can I do it with xz? I mean I will need tar too because I can't compress a directory with only xz. Is there a oneliner to produce e.g. foo....
user avatar
  • 36.4k
109 votes
7 answers
151k views

Create a tar archive split into blocks of a maximum size

I need to backup a fairly large directory, but I am limited by the size of individual files. I'd like to essentially create a tar.(gz|bz2) archive which is split into 200MB maximum archives. ...
user avatar
  • 35.8k
104 votes
8 answers
21k views

Why would I tar a single file?

At my company, we download a local development database snapshot as a db.dump.tar.gz file. The compression makes sense, but the tarball only contains a single file (db.dump). Is there any point to ...
user avatar
  • 1,927
104 votes
14 answers
270k views

tar --exclude doesn't exclude. Why?

I have this very simple line in a bash script which executes successfully (i.e. producing the _data.tar file), except that it doesn't exclude the sub-directories it is told exclude via the --exclude ...
user avatar
  • 1,537
102 votes
6 answers
262k views

How to add/update a file to an existing tar.gz archive?

Is there a way to add/update a file in a tar.gz archive? Basically, I have an archive which contains a file at /data/data/com.myapp.backup/./files/settings.txt and I'd like to pull that file from the ...
user avatar
  • 35.8k
101 votes
5 answers
108k views

How to download an archive and extract it without saving the archive to disk?

I'd like to download, and extract an archive under a given directory. Here is how I've been doing it so far: wget http://downloads.mysql.com/source/dbt2-0.37.50.3.tar.gz tar zxf dbt2-0.37.50.3.tar.gz ...
user avatar
  • 4,045
97 votes
7 answers
150k views

creating a tar archive without including parent directory

I am trying to create a graphical program for my script. Inside the script I use tar to create a tar archive. From the graphical program I get the full name of file that I want to create a tar ...
user avatar
87 votes
4 answers
162k views

tar exits on "Cannot stat: No such file of directory", why?

I'm trying to create tar.gz file using the following command: sudo tar -vcfz dvr_rdk_v1.tar.gz dvr_rdk/ It then start to create files (many files in folder), but then I get the following error: tar:...
user avatar
  • 1,357
82 votes
3 answers
164k views

scp and compress at the same time, no intermediate save

What is the canonical way to: scp a file to a remote location compress the file in transit (tar or not, single file or whole folder, 7za or something else even more efficient) do the above without ...
user avatar
81 votes
12 answers
92k views

How can I best copy large numbers of small files over scp?

I have a directory that's got several gigabytes and several thousand small files. I want to copy it over the network with scp more than once. CPU time on the source and destination machines is cheap, ...
user avatar
  • 910
79 votes
2 answers
90k views

How to create backup from symbolic links?

I have a directory with symbolic links to other directories. I want to archive the symbolic links, not as links but as archives containing the files of directories they refer to, using tar command. ...
user avatar
  • 2,244
60 votes
6 answers
58k views

What are the differences between bsdtar and GNU tar?

I've always used GNU tar. However, all GNU/Linux distributions that I've seen ship bsdtar in their repositories. I've even seen it installed by default in some, IIRC. I know for sure that Arch GNU/...
user avatar
  • 14.1k
56 votes
4 answers
164k views

How to create tar archive in a different directory?

I want to create a tar archive in a different directory rather than the current directory. I tried this command: tar czf file.tar.gz file1 -C /var/www/ but it creates the archive in the current ...
user avatar
  • 3,071
53 votes
4 answers
40k views

Does tar actually compress files, or just group them together?

I usually assumed that tar was a compression utility, but I am unsure, does it actually compress files, or is it just like an ISO file, a file to hold files?
user avatar
  • 905
51 votes
8 answers
65k views

Is there a parallel file archiver (like tar)?

Is there something out there for parallel archiving of files? Tar is great, but I don't use tape archives, and it's more important to me that the archiving happens quickly (with compression like ...
user avatar
50 votes
3 answers
110k views

Extract multiple .tar.gz files with a single tar call

I was wondering whether (and, of course, how) it’s possible to tell tar to extract multiple files in a single run. I’m an experienced Unix user for several years and of course I know that you can use ...
user avatar
  • 663
49 votes
5 answers
91k views

Create target directory when extracting tarball

Is it possible to create a target directory, similar to mkdir -p, where I can define a non-existent target directory within my tar command, and tar will create the directory for me? I know I can ...
user avatar
49 votes
1 answer
46k views

ansible extract without first directory

When extracting a tar.gz file in ansible I end up with a first directory - name: Extract archive unarchive: src=file.tar.gz dest=/foo/bar which results in /foo/bar/bar-version-...
user avatar
47 votes
4 answers
119k views

Why can't tar extract .zip files? [closed]

I tried a majority of the formats (gzip, etc.) to extract a zip file with tar, and when I became frustrated enough to Google for it, I found no way to extract a zip file with tar and only ...
user avatar
  • 583
45 votes
5 answers
13k views

Why use superflous dash (-) to pass option flags to tar?

To create a tar file for a directory, the tar command with compress, verbose and file options can be typed thus: $ tar -cvf my.tar my_directory/ But it also works to do it this way: $ tar cvf my....
user avatar
42 votes
5 answers
73k views

How to solve “tar: invalid magic” error on Linux Alpine

I'm installing sqlite on Alpine Linux. I download sqlite-autoconf-3130000.tar.gz but tar could not open it. I tried this answer but it's not working. tar gives this message: tar: invalid magic tar: ...
user avatar
  • 521
41 votes
7 answers
30k views

tar extraction depends on filename?

I often download tarballs with wget from sourceforge.net. The downloaded files then are named, e.g SQliteManager-1.2.4.tar.gz?r=http:%2F%2Fsourceforge.net%2Fprojects%2Fsqlitemanager%2Ffiles%2F&ts=...
user avatar
  • 413
37 votes
1 answer
111k views

Is there a way to tar multiple files in a directory (Linux/Unix)?

Is there a fairly simple way to tar several (specific) files in a directory? For example let's say the following is a directory: -rw-r--r-- 1 allend bin 98 Jul 20 15:50 scriptlog.log -rw-r--r-- 1 ...
user avatar
  • 2,227
37 votes
5 answers
4k views

How to untar safely, without polluting the current directory in case of a tarbomb?

Respectable projects release tar archives that contain a single directory, for instance zyrgus-3.18.tar.gz contains a zyrgus-3.18 folder which in turn contains src, build, dist, etc. But some punk ...
user avatar
35 votes
4 answers
62k views

Fastest way combine many files into one (tar czf is too slow)

Currently I'm running tar czf to combine backup files. The files are in a specific directory. But the number of files is growing. Using tzr czf takes too much time (more than 20 minutes and counting)....
user avatar
35 votes
3 answers
78k views

Test tar file integrity in bash

I have a bash script that creates a '.tar' file. Once the file is created, I would like to test its integrity and send an email to the root user if the integrity is bad. I know I would need to use ...
user avatar
  • 1,107
34 votes
5 answers
36k views

Tar a folder without .git files?

If I tar a folder that is a git repository, can I do so without including the .git related files? If not, how would I go about doing that via a command?
user avatar
  • 7,703
34 votes
2 answers
5k views

Why is tar archive so much bigger than text file, 10240 bytes?

I've checked these two questions (question one, question two), but they were not helpful for me to understand. I have a file file.txt with 40 lines of Hello World! string. ls -l shows that its size is ...
user avatar
34 votes
2 answers
45k views

Prevent showing time stamp message when running "tar xzf"

When running tar xzf, how to prevent this message (Prevent showing time stamp message): tar: node: time stamp 2011-06-07 02:02:30 is 8309 s in the future tar: user/Node: time stamp 2011-06-07 01:56:...
user avatar
34 votes
4 answers
50k views

What does --strip-components -C mean in tar?

I want to make sure I understand the following code: tar xvzf FILE --exclude-from=exclude.me --strip-components 1 -C DESTINATION which was posted in this answer. From man tar: --strip-components=...
user avatar
32 votes
4 answers
67k views

tar with relative paths

I try to create an archive with tar using relative paths. I use the following command: tar czf ~/files/wp/my-page-order.tar.gz -C ~/webapps/zers/wp-content/plugins/ ~/webapps/zers/wp-content/plugins/...
user avatar
31 votes
3 answers
8k views

How do I securely extract an untrusted tar file?

I would like to be able to extract a tar file, such that all extracted files are placed under a certain prefix directory. Any attempt by the tar files to write to outside directories should cause the ...
user avatar
  • 505
30 votes
5 answers
52k views

View a file in a tar archive without extracting it

I want to view the content of the tarred file without extracting it, Scenario: I have a.tar and inside there is a file called ./x/y.txt. I want to view the content of y.txt without actually ...
user avatar
  • 301
30 votes
3 answers
44k views

Encrypting and compressing

Is there a better way to compress and then encrypt files other than tar followed by openssl or gpg?
user avatar
  • 613
29 votes
2 answers
2k views

Is it true that a tarball can change where files are extracted to regardless of the commands used to extract it?

I have a coworker who says you need to be careful extracting tarballs because they can make changes you don't know about. I always thought a tarball was just a hierarchy of compressed files, so if you ...
user avatar
29 votes
7 answers
61k views

tar + rsync + untar. Any speed benefit over just rsync?

I often find myself sending folders with 10K - 100K of files to a remote machine (within the same network on-campus). I was just wondering if there are reasons to believe that, tar + rsync + ...
user avatar
29 votes
7 answers
28k views

What to use to backup files, preserving ACLs?

When using the tar utility to store files in backups one loses the extended ACLs. Is there some commonly used and not hackish solution (like: create a script that will recrate the ACLs from scratch) ...
user avatar
  • 1,382
27 votes
5 answers
41k views

How do I compress files in-place?

I have a machine with 90% hard-disk usage. I want to compress its 500+ log files into a smaller new file. However, the hard disk is too small to keep both the original files and the compressed ones. ...
user avatar
  • 6,847
27 votes
3 answers
20k views

What does the -f parameter do in the tar command

When using tar I always include -f in the parameters but I have no idea why. I looked up the man and it said; -f, --file [HOSTNAME:]F use archive file or device F (default "-", meaning stdin/stdout)...
user avatar
  • 3,635
26 votes
3 answers
40k views

tar cvf or tar -cvf ?

I have learned to use tar without '-' for options, like tar cvfz dir.tar.gz Directory/ but I recently came accross the slightly different tar -czvf syntax (I think the 'f' must be the last option in ...
user avatar
  • 459
26 votes
6 answers
20k views

How can I determine if running tar will cause disk to fill up

If I run tar -cvf on a directory of size 937MB to create an easily downloadable copy of a deeply nested folder structure, do I risk filling the disk given the following df -h output: /dev/xvda1 ...
user avatar
  • 3,142
26 votes
1 answer
51k views

Will tar -cvzf packed.tar.gz mydir take hidden files into account?

I need to create a tarball of a given directory. However, I need to make sure hidden files are included too (such as those beginning with .). Will the following command automatically take the hidden ...
user avatar
25 votes
2 answers
11k views

Dereferencing hard links

In the manual page of tar command, an option for following hard links is listed. -h, --dereference follow symlinks; archive and dump the files they point to --hard-dereference follow ...
user avatar
  • 968
24 votes
5 answers
41k views

tar without preserving user [duplicate]

I'd like to compress some files for http distribution, but found that .tar.gz keeps the user name and user ID and there doesn't seem to be any way to not do that? (There is a --numeric-owner option ...
user avatar
24 votes
5 answers
40k views

tar extract into directory with same base name?

I have a ziped file like myArchive123.tar.gz. Inside it contains a folder like helloWorld If I extract it: tar -xf myArchive123.tar.gz I get the helloWorld folder: ls myArchive123.tar.gz helloWorld ...
user avatar

1
2 3 4 5
24