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 ...