tar: commands you should know

There is a well known tool in the Unix world, and that is tar, since tarballs are handled daily, especially for unpacking source code packages and compiling them. As you already know, if you read us, tarballs are files packed with the tar tool and with some type of compression, which can be of different types depending on the compression algorithm used. Therefore, other compression / decompression tools are used.

The good thing about tarballs is that keep the permissions and other attributes of the packaged files and directories, that is why they are especially important to preserve the proper permissions of the source files, scripts and others that we must execute for compilation and installation. In fact, when we "unpack" one of these packages badly, using for example some graphical decompression tools, those permissions are destroyed and what we intend may not work correctly ...

Today we are going to present you some simple and basic commands with tar that you should know to be able to work well with packages. For more information, you can consult other of my articles such as:

Well, let's do it:

  • Package a file or directory:
tar -cvf nombre_tarball.tar /ruta/directorio/ 
  • For .gz compression (if you want another type of compression, you can change the z to j for .bz2, etc.):
tar cvzf nombre_tarball.tar.gz /ruta/directorio/
  • To unpack, with the x, whatever the compression:
tar -xvf nombre_tarball.tar.gz
  • Just list the contents of the tarball, without exerting any decompression or unpacking operation on it:
tar -tvf nombre_tarball.tar.gz
  • Add files and directories to an existing tarball:
tar -rvf nombre_tarball.tar.gz nuevo.txt
  • Check a tarball:
tar -tvfW nombre_tarball.tar
  • Check the size:
tar -czf - nombre_tarball.tar.gz | wc -c

The examples I have put them with .gz compression normally, but it doesn't have to be that way. It was the same for .bz2, .xz, etc. Just remember when compressing, use the appropriate font for each type of compression ...

 


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

A comment, leave yours

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   George said

    Hello,
    For .gz compression (if you want another type of compression, you can change the z to j for .bz2, etc.) ...
    Wouldn't it be .gz for .bz2?
    tar cvzf tarball_name.tar.gz / path / directory /
    Wouldn't tar -cvzf tarball_name.tar.gz / path / directory /?
    tar -czf - tarball_name.tar.gz | wc -c
    Why does it not give the same result as if we look at it in Properties)

    Thanks. Greetings from Perillo (Oleiros) - A Coruña.