10/3/2023 0 Comments Untar linux terminal![]() Let’s suppose we have to take backup of whole /opt folder on daily basis, this can be achieved by creating a cron job of tar command. There are some real time scenarios where we have to create tar file of specific files and directories for backup purpose on daily basis. # tar xpvf archive.tbz2 -C /tmp/ 14) Scheduling backup with tar command Example is shown below # tar -jxpvf archive.tbz2 -C /tmp/ tbz2 is extracted using the option ‘-j’ and ‘-x’. tbz2)Īrchive files with extension tar.bz2 or. Example is shown below : # tar -xpvf archive.tgz -C /tmp/ 13) Extract compressed archive (tar.bz2 or. ![]() Note : Now a days tar command will take care compression file types automatically while extracting, it means it is optional for us to specify compression type in tar command. tgz is extracted with option ‘-x’ and ‘-z’ as shown below, # tar -zxpvf archive.tgz -C /tmp/Ībove command will extract tar file under /tmp directory. Example is shown below : # tar -tvf archive.tbz2 | moreġ2) Extract compressed archive file (tar.gz or. tbz2)Ĭontent of tar file with the extensions. Example is shown below : # tar -tvf archive.tgz | moreġ1) List the content of compressed archive (tar.bz2 or. tgz)Ĭontents of compressed archive with extension tar.gz or. Let’s assume we want to exclude the file type of html while creating the compressed tar file, run # tar -zcpvf archive.tgz /var/ /opt/ -exclude=*.html 10) List the content of compressed archive (tar.gz or. Using “–exclude” option in tar command we can exclude the specific file type while creating archive file. # tar -jcpvf archive.tbz2 /etc/ /opt/ 9) Exclude specific file type while creating archive Extensions of such tar files will be either tar.bz2 or. ![]() This can be achieved by using the option (-j) in the tar command. Let’s assume that we want to create compressed (bzip2) tar file of /etc and /opt folder. # tar -zcpvf archive.tgz /etc/ /opt/ 8) Create and compress archive file (bzip2) Extensions of such tar files will be either tar.gz or. This can be achieved using ‘-z’ option in tar command. We can compress archive file while creating it, let’s assume that we want to create a tar file of /etc and /opt folder and also want to compress it using gzip tool. # 7) Create and compress archive file (gzip) rw-r-r- 1 root root 104 Aug 9 12:55 etc/netplan/01-network-manager-all.yaml # ls -l etc/netplan/01-network-manager-all.yaml Syntax : # tar -xvf # tar -xvf archive.tar etc/netplan/01-network-manager-all.yaml Let’s suppose we want to extract “/etc/netplan/01-network-manager-all.yaml” file from the archive under /tmp folder. Example is shown below # tar -xvf archive.tar -C /tmp/ 6) Extract specific file from tar archive In case you want to extract tar file to a specific folder or directory then use ‘-C’ option followed by path of a folder. 5) Extract tar archive to specific folder # tar -xvf archive.tarĪbove command will extract all the files and directories of archive.tar file in the current working directory. To extract an archive file, use ‘-x’ option in the tar command as shown below. Note: In the Compressed tar file we can’t append file or directory. Verify whether file is appended or not, run # tar -tvf archive.tar var/log/auth.log Let’s add /var/log/auth.log file to archive.tar, run # tar -rvf archive.tar /var/log/auth.log ‘-r’ option in the tar command is used to append or add file to existing archive file. In the below example, we are trying to list whether ‘syslog’ file is there in the tar file or not. ![]() Listing a specific file or directory from tar file. Use ‘-t‘ option in tar command to view the content of tar files without extracting it. In above command, ‘-c’ option specify to create a tar file, ‘ -v’ is used for verbose output and ‘-f’ option is used to specify the archive name. Tar file contains all the files and directories of /etc folder and /var/log/syslog file. Let’s create a tar file of /etc directory and ‘/root/anaconda-ks.cfg’ file, run # tar -cvf archive.tar /etc /var/log/syslogĪbove command will create a tar file with the name “archive.tar” in the current folder. Without any further delay, let’s jump into tar command examples. Note: hyphen ( – ) in the tar command while using options is optional. -z, –gzip : Compress and extract the archive through gzip.-J, –xz : Compress and extrach the archive through xz.-j, –bzip2 : Compress and extract archive through bzip2.-C, –directory=DIR: Change to DIR before performing any operations.-X, –exclude-from=file : exclude patterns listed in file.-u, –update : only append files newer than copy in archive.-r, –append : append files to the end of an archive.-d, –diff, –compare : find differences between archive and file system.-x, –extract, –get : extract files from an archive.-t, –list : list the contents of an archive.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |