Questions tagged [tar]

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

1261 questions
413
votes
2 answers

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 completely lost and I've been at this for hours now. Not sure if…
qwerty
  • 4,271
  • 5
  • 16
  • 13
229
votes
6 answers

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 --extract --file={test.tar.gz} {extract11} tar:…
Ankit Vashistha
  • 3,487
  • 12
  • 31
  • 36
215
votes
9 answers

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 ?
superuser
  • 2,251
  • 2
  • 13
  • 6
206
votes
1 answer

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...
Garrett Hall
  • 5,121
  • 5
  • 19
  • 12
198
votes
5 answers

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?
tshepang
  • 64,472
  • 86
  • 223
  • 290
161
votes
13 answers

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.tar.xz?
LanceBaynes
  • 39,295
  • 97
  • 250
  • 349
121
votes
7 answers

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. Clonezilla does something similar to this by splitting…
Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311
119
votes
6 answers

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 mv dbt2-0.37.50.3 dbt2 I'd like instead to…
BenMorel
  • 4,447
  • 8
  • 36
  • 46
115
votes
5 answers

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 archive (already done) and push it back into the…
Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311
110
votes
14 answers

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 option: /bin/tar -cf /home/_data.tar …
ateiob
  • 1,627
  • 4
  • 14
  • 12
108
votes
7 answers

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 archive. tar -cvf temp.tar…
Sujit Maharjan
  • 1,395
  • 3
  • 9
  • 10
105
votes
8 answers

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 archiving a single file, or is .tar.gz just such a…
gardenhead
  • 1,997
  • 2
  • 12
  • 12
92
votes
5 answers

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: dvr_rdk_v1.tar.gz: Cannot stat: No such file or…
ransh
  • 1,397
  • 2
  • 10
  • 19
89
votes
3 answers

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 saving intermediate files I am familiar with shell…
Robottinosino
  • 5,271
  • 12
  • 39
  • 51
88
votes
13 answers

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, but the network overhead added by copying each…
nmichaels
  • 980
  • 1
  • 7
  • 8
1
2 3
84 85