How do I compress a tar file in Linux

How do I compress a tar file in Linux

Hi,

I want to create the tar.gz file file of a directory in Linux. My directory contains many sub directories and many files are there inside it.

I want to know the tar command for creating tar of directory and all the contents inside it. the created tar file should include all the directories and files inside the main directory.

Tell me the command for this.

Thanks

View Answers

February 10, 2020 at 12:30 AM

Hi,

The tar command was first introduced in the seventh edition of unix v7 in January 1979. Since then it is being used by the Linux and Unix users around the world. This command comes with many features to work with files and directories.

The tar command can be used to work with files and directories, and it can be used to compress and decompress the files and directories with following informations:

  • File names - Inside the tar file names are well preserved.
  • Directory structure - Inside the tar file, Directory structure are well preserved.
  • File permission - Inside the tar file, File permissions are well preserved.
  • SELinux permissions - Inside the tar file, SELinux permissionss are well preserved.
  • Timestamps - It also preserve the timestamps details
  • File ownership - You can also preserve the file ownership
  • File access permissions and more - It also offers to save the file access permissions.

Here is command to create tar file:

tar -czvf myfile.tar.gz mydir

Thanks


April 22, 2020 at 3:37 PM

Hi,

Check the following tutorial for more examples:

Thanks









Related Tutorials/Questions & Answers:
How do I compress a tar file in Linux
How do I compress a tar file in Linux  Hi, I want to create the tar.gz file file of a directory in Linux. My directory contains many sub directories and many files are there inside it. I want to know the tar command
How do I compress a tar file in Linux
How do I compress a tar file in Linux  Hi, I want to create the tar.gz file file of a directory in Linux. My directory contains many sub directories and many files are there inside it. I want to know the tar command
Advertisements
How do I compress a tar file in Linux
How do I compress a tar file in Linux  Hi, I want to create the tar.gz file file of a directory in Linux. My directory contains many sub directories and many files are there inside it. I want to know the tar command
how to check the size of a tar file in linux
how to check the size of a tar file in linux  Hi, I want to check the size of tar file in Linux. How to check the size of a tar file in linux? What Linux command I should use to check the size of a tar file? Thanks
How do I tar a directory without retaining the directory structure?
How do I tar a directory without retaining the directory structure?  Hi, I want to create tar file without retaining the directory permission. How to do this? Thanks   Use tar czf ~/backup.tgz Thanks
How do I tar a directory without retaining the directory structure?
How do I tar a directory without retaining the directory structure?  Hi, I want to create tar file without retaining the directory permission. How to do this? Thanks   Use tar czf ~/backup.tgz Thanks
how to create tar file in ubuntu
how to create tar file in ubuntu  Hi, I have a directory with many sub directories and files in it. I want to create tar file of the directory so that it can be moved to another computer easily. I am searching for command to do
how to create tar file in ubuntu
how to create tar file in ubuntu  Hi, I have a directory with many sub directories and files in it. I want to create tar file of the directory so that it can be moved to another computer easily. I am searching for command to do
linux tar folder and subfolders
for me for zipping it into a file possible Linux tar file. I just searched and found...linux tar folder and subfolders  Hi, I am new to Linux operating..., I want a simple way to compress these files preserving the directory structure
How to compress a file in Java?
How to compress a file in Java?  How to compress a file in Java through Java code? I want a good example in Java. Thanks   Hi, Check the tutorial Compressing the file into GZIP format. Thanks
How do I import a CSV file in R?
How do I import a CSV file in R?  Hi, I have a CSV file with 900000 records and I want to load it for analytics. How do I import a CSV file in R... file: data = read.csv("data.csv", header = TRUE) Above code loads the data
How do I install a .deb file via the command line?
How do I install a .deb file via the command line?  How do I install a .deb file via the command line?   Hi, You can install it with following command: sudo dpkg -i DEB_PACKAGE Example: sudo dpkg -i packagename.deb
how do i upload a file by using servlet or jsp?
how do i upload a file by using servlet or jsp?  hi plz tell me the write java code
How do I read a variable from a file in shell script
How do I read a variable from a file in shell script  Hi, In my project we are submitting the job on spark cluster through sh file. Now I want... command. How do I read a variable from a file in shell script and then use
how do i allow users to download a xls file in html?
how do i allow users to download a xls file in html?  can anyone help me to allow users to download a xls file in html? i tried with href="path...;i tried with href="path/filename.xls click here but it works only in chrome
How do I read a large file quickly in Java?
How do I read a large file quickly in Java?  Hi, I my project I have to read vendor feed which comes in text file. Size of the file is usually in 1-2 GB in size. What is the best way to read the file efficiently? How do I read
How do I upgrade mysql?
How do I upgrade mysql?  How do I upgrade mysql
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want...("a"); x.click(); </script> So it's click on an element witch one Id's is "a", but I want that it make mouseup in this element. How can I do it, because if I write
What changes I have to do in php.ini file for file uploading?
What changes I have to do in php.ini file for file uploading?  What changes I have to do in php.ini file for file uploading
how do i solve this problem?
how do i solve this problem?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access
how do i solve this question?
how do i solve this question?  1.Define a class named Circle with the following properties: a) An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier
How do i do the coding for 'leaving a comment' in java
How do i do the coding for 'leaving a comment' in java  i am designing a webpage.In my webpage i want to add the option of adding a comment by the readers of the page.how do i do
How do I initialize a byte array in Java?
How do I initialize a byte array in Java?  How do I initialize a byte array in Java
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
How do I compare strings in Java?
How do I compare strings in Java?  How do I compare strings in Java
How do I compile the registration form?
How do I compile the registration form?  How do I compile the registration form as stated at the bottom of the following page (URL is below). Do I need ANT? If so, please give instructions. I am a student. http
How to Compress file using DeflaterOutputStram class in java.
How to Compress file using DeflaterOutputStram class in java. In this tutorial, we will discuss  how to use DeflaterOutputStream class in java... will compressed the data of a file by using DeflaterOutputStream class
How do I get started with Bootstrap
How do I get started with Bootstrap  Hi, I am new to Bootstrap and want to learn it in. What all things I should know before starting Bootstrap? How do I get started with Bootstrap? Thanks
How do I get started with Bootstrap
How do I get started with Bootstrap  Hi, I am new to Bootstrap and want to learn it in. What all things I should know before starting Bootstrap? How do I get started with Bootstrap? Thanks
tar directory and subdirectories
tar directory and subdirectories  Hi, I am developing program on Linux machine. I have to create the .tar file of a directory and subdirectories. How I can tar directory and subdirectories? Thanks   Hi, It's very
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
How do I study big data?
How do I study big data?  Hi, I am a Java Programmer. How do I study big data? Thanks   Hi, You learn like this: Install Hadoop Learn Hadoop Learn Hadoop Framewors Check topics: Big Data and Hadoop Training
How do I start machine learning with Python? What should I do if I am a beginner?
How do I start machine learning with Python? What should I do if I am... am searching for the tutorials to learn: How do I start machine learning... or tutorials links so that I can learn the topic "How do I start machine
How do I generate random number?
How do I generate random number?  In my Java program there is a requirement of generating random numbers between two given numbers. How do I write code for generating the random number? Thanks   Hi
How do I do this program? I'm new to Java programming...
How do I do this program? I'm new to Java programming...  Suppose you want to print out numbers in brackets, formatted as follows: [1] [2] [3] and so on. Write a method that takes two parameters: howMany and lineLength
how do i grab the url in php?
how do i grab the url in php?  I want to grab the 'entire' url, including any special characters like & and #, from a site. I then want... # = %23 I tried URL encoding but it only grabs the part until the #, which
How do I start learning MongoDB?
How do I start learning MongoDB?  Hi, What are the correct steps of learn MongoDB? How do I start learning MongoDB? What is MongoDB and how I can... MongoDB: What is it and it's Features? How to install MongoDB On Windows 7? After
How do I download urllib3 for python 2.7
How do I download urllib3 for python 2.7  Hi, How do I download urllib3 for python 2.7? I want to install urllib3 on Python 2.7. How to do this? Thanks   Hi, You can use the pip installer for installing urllib3
How do I learn Python data science?
How do I learn Python data science?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How... links so that I can learn the topic "How do I learn Python data science
How do I start a data mining company?
How do I start a data mining company?  Hi, I am beginner in Data...: How do I start a data mining company? Try to provide me good examples or tutorials links so that I can learn the topic "How do I start a data mining
How do I get a job in AI field?
How do I get a job in AI field?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How do... that I can learn the topic "How do I get a job in AI field?". Also
How do I start learning AI?
How do I start learning AI?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How do I... can learn the topic "How do I start learning AI?". Also tell me which
How do I become an AI engineer?
How do I become an AI engineer?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How do... that I can learn the topic "How do I become an AI engineer?". Also
How can I do data science course?
How can I do data science course?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How... so that I can learn the topic "How can I do data science course?"
How do I become a data scientist in India?
How do I become a data scientist in India?  Hi, I am beginner... to learn: How do I become a data scientist in India? Try to provide me good examples or tutorials links so that I can learn the topic "How do I become a data
How do I prepare for a data scientist interview?
How do I prepare for a data scientist interview?  Hi, I am beginner... to learn: How do I prepare for a data scientist interview? Try to provide me good examples or tutorials links so that I can learn the topic "How do I

Ads