The following command list the contents of the tar archive file named : tar -tvf What about you want to see the archive file contents? It's possible to see the content of a tar file without extracting it. tar -xzvf -C /home/linuxopsys/documents List the contents of Archive file In case you want to extract the archive to a specific directory use -C option. Extract files to a specific directoryĪbove we saw the content of the archive is extracted to the current directory. The content of the archive file will be extracted to the current directory. To extract or untar archive file named, run the following command: tar -xzvf The exclude switch also accepts patterns such as -exclude=*.jpg. ![]() tar -czvf Projects -exclude=/home/linuxopsys/CSS -exclude= /home/linuxopsys/data -exclude=*.jpg When compressing you can exclude specific directories or files using -exclude switch. To compress multiple files into one archive file, type: tar -czvf doc1.txt doc2.txt doc3.pdf Exclude Directory when creating Archive File The following command compress directories to an archive file named in the current directory: tar -czvf /path/to/directory1 /path/to/directory2 Compress Multiple Files You can use replace -z with -j option to compress using bzip2 algorithm. The above command will create an archive file named in the current directory. You need to use -z option for gzip and -j option for bzip2 algorithm.įor example to compress a directory named projects using gzip and save the file as, type: tar -czvf /home/foo/documents You can tell the tar command to create archive files with compression using various algorithms. This creates tar files, it is used to just bundle a bunch of files or directories Compress a Whole Directory tar -cvf move.tar file.txt file2.txt file2.txt To create an archive file without any compression using -cvf option. Let's check more into the Linux Tar command and its usage with examples. Example: tar -czvf -P /path/to/directory-or-the-file Tar Command Examples If you get a message saying "tar: Removing leading `/' from member names" it's only information you can use -P option or remove the absolute path. To compress a directory or a file in Linux, use the following syntax: tar -czvf /path/to/directory-or-the-fileįor example to compress the directory named Projects in the current directory and save it with the name project-archive-tar.gz, type: Tell tar command to compress the archive using bzip2 compression algorithm Tell tar command to compress the archive using gzip compression algorithm Verbose mode, show the progress when creating the archive file Some of the important tar options are: Options ![]() Tar can use different compression algorithms to create tarballs which having extensions such. ![]() Tar command is generally used to compress files and directories into a single archive. The compressed archive file or called tarballs will have extensions such as. tar archive (uncompressed) and compress it using compression algorithms such as xz, gzip, and bzip2. The tar command is used in Linux to create compressed or uncompressed archives containing a set of files or a single file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |