107

I have a very large folder of 120,000+ files. and I need to move them to another location on my same machine (same partition).

I'd like to use the tar command to group them up as a single unit and then mv them to the end location.

What command do I need to run to tar them all together and not compress anything (I need the fastest result).

2
  • 1
    Why use tar, and not just mv(1) the files? Or use cp(1) if you don't want to lose the originals?
    – vonbrand
    Jan 11, 2013 at 17:58
  • 2
    @vonbrand one might want to rsync over the network one single continuous file. much faster than rsyncing 120k smaller files. it's the difference between constant full speed to highs and lows
    – mwm
    Nov 29, 2018 at 12:19

2 Answers 2

158

tar does not compress by default, just don't add a compression option:

tar -cvf myfolder.tar myfolder

I am including Hennes' comment in my answer since it adds useful information:

TAR (tape archive) is originally a unix program used to create archives on tape. Since all devices are treated as files under unix it is easy not to write to a tape but to a file instead. This is usually done with the -f flag. The command tar cvf myfolder.tar myfolder means tar, create, verbose file filename_to_create what_to_tar. There is no compression in this anywhere. Tar archives (as files) where often compressed using the compress program and gained the extention .Z (e.g. file.tar.Z). Later on this got included in gtar with the z flag

5
  • Will that recursively add all subfolder and files in the tar?
    – sergserg
    Jan 8, 2013 at 15:51
  • 2
    @Serg yes, it will.
    – terdon
    Jan 8, 2013 at 15:54
  • 1
    Thanks. I usually try to answer in both short and long form. As in "yes/no it will [not] work" for the short one, and an explanation as to why as the longer answer. Having the background as to why often helps in the future.
    – Hennes
    Jan 8, 2013 at 16:01
  • 1
    @Serg as it's not always the case that a manual or instructions are so good that they make things clear just straight away reading them, sometimes the best way is to go ahead and try the command anyway, then you'll see what it does, and once you know what it does or have a good idea then the manual can confirm that for you! it's easy to test tar on a small example set of files.with examples of how to use it, without having to make head or tail of the manual.
    – barlop
    Jan 20, 2013 at 17:59
  • 2
    Note that if the fastest results are desired you should omit the "v" flag to silence output. In my case this reduced command time from 16 seconds to 6 seconds when running it on an AWS t2.medium instance. Sep 4, 2019 at 7:26
14

The @terdon answer is right.

But I made a small mistake doing tar cvf myfolder.tar.gz myfolder. I wanted same ending names for the files in the same path tar.gz even when it's not compressed.

So, if you put something like .gz, .z at the end of the filename you're trying to tar, the tar app will understand you want to use some compression, and it will apply accordingly to what you put (gz = gzip).

So if you want to use a extension like that tar.gz, make sure to use the flag --no-auto-compress

--no-auto-compress    do not use archive suffix to determine the compression 
program

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .