How To Tar a Directory In Linux With Examples?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To tar a directory in Linux, use the tar command. To create a tar file of a directory, execute the following command from the command line:
tar –cf [tar file name] [directory to be tarred]
For example, to create a tar file of a directory named mydir, execute the following command:
tar –cf mydir.tar mydir To extract the contents of the tar file afterwards, execute the following command:
tar –xf [tar file name] For example, to extract the contents of the tar file mydir.tar, execute the following command:
tar –xf mydir.tar
1. To tar a directory, use the tar command followed by the flags -cvf. For example, to tar up a directory named “mydir”, use the command:
tar -cvf mydir.tar mydir
2. The “-c” option tells tar to create an archive from the specified files, the “-v” option tells tar to be verbose, and the “-f” option tells tar to create an archive with a specified filename.
3. To compress the tar archive, use the “-z” option. For example, to create a gzipped tar archive of “mydir”, use the command:
tar -czvf mydir.tar.gz mydir
4. To extract a tar archive, use the tar command followed by the flags -xvf. For example, to extract the tar archive “mydir.tar”, use the command:
tar -xvf mydir.tar