![]() ![]() Now that you have your tar archive ready, the next step is to compress it in order to reduce its size.įor that, we are first going to use the gzip utility.īy default, the gzip utility should be installed, but if this is not the case, make sure to install it depending on your distribution. Quite handy when you are afraid of losing your content! Compressing files using gzip on Linux Star: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k). Now if you were to create a file with the exact same name, the star utility would not overwrite it by default. $ gzip archive.tarĪs a consequence, the initial tar file will be transformed into a tar.gz archive. Then, you can use the gzip or gunzip utility in order to compress your new archive. Then, in order to archive files with star, simply run “star” with the “-c” option. In order to install the star utility, run the YUM utility $ sudo yum install star Prevent file overwriting using starīy default, the star utility might not be installed on your system. In order to avoid erasing your files, you can use the star command which is a great alternative to the existing tar command. Similarly, tar can inspect file sizes and highlight size differences between your files. If the modification date of the local file is more recent than the one from the archive file, the tar command will display a notice showing that the modification time differs. $ tar -dvf archive.tarĪs you can see, tar will compare timestamps and more specifically the latest modification date of the file. In order to compare files with tar, use the “-d” option. ![]() $ echo "Added some content to the file" > file1 In order to prevent data to be erased during the process, the tar command can compare files located in your current working directory with files in your archive.īack to the example we discussed earlier, let’s add some content back to the “file1” file. Comparing local files with archive files ![]() In order to illustrate it, add some content to one of your file, extract your files and re-inspect the content of your file again. If a file on the current working directory has the same name as a file inside the archive, the content of the file in the working directory will be replaced with the one from the archive. When extracting files on Linux, there a little gotcha that you need to be aware of. rw-rw-r- 1 schkn schkn 0 Nov 9 12:00 file1 Note that extracting your files does not mean that the archive will be deleted from your current working directory. To extract files using the tar command, append the “ -x” option instead of the initial “-c” option. Now that you have created an archive file, you may want to extract the files located in your archive. In order to compress files when archiving, you need to provide other options to the tar command.įile compression will be explained in the next chapters. This is a very important fact because we are able to understand that archiving files does not mean that your files are compressed in it. rw-rw-r- 1 schkn schkn 0 Nov 9 10:41 file2Īs you can see, the size of the archive is bigger than the sum of the files in it.Ĭreating a tar archive does not simply put files and directories in a big box : an archive is also a special file made of special file headers that may take a substantial amount of space.Īs a consequence, your archive is way bigger than the sum of the files in it. rw-rw-r- 1 schkn schkn 0 Nov 9 10:41 file1 rw-rw-r- 1 schkn schkn 10240 Nov 9 10:41 archive.tarĭrwxrwxr-x 2 schkn schkn 4096 Nov 9 10:41 directory1ĭrwxrwxr-x 2 schkn schkn 4096 Nov 9 10:41 directory2 When running the tar command with the “-f” flag, a new archive was created in your current working directory. Those options are probably the most important options for archiving files on Linux. -f : for file, this option is used in order to specify the filename of the archive we want to create (in this case archive.tar).-v : for verbose, this is the reason why the command displays the files added to the archive when executing it.-c : for create archive, a pretty self-explanatory option if you want to create a new archive made from the files selected.In this case, we used three different options : $ tar -cvf archive.tar file1 file2 directory1 directory2 To archive files on Linux using tar, run “ tar” with the “ cvf” options. Nowadays, the tar command is widely used in order to archive files (meaning putting files together in a single archive). Sometimes referred as tarball, tar was historically used to write data to devices that did not have file systems at the time.Īs a consequence, the tar command was introduced in 1979 in order to replace the “ tp” program that was used back then. Tar is a very popular command among system administrators. Comparing local files with archive files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |