How to compress a whole directory in Linux using gzip format?
|
|
|
|
|
Question: How to compress a whole directory in Linux using gzip format via the command line? Answer: This is a perfect way of creating backups of your files and folders or emailing files to a friend or colleague. This could also be called a compressed archive. First this command creates the archive and then it compresses the archive. Lets put it to practice You have a directory called documents where all your important documents are stored. And you would like to archive and compress this directory for backup purposes using GZIP. You will execute the following command via the command line: tar -zcvf documents.tar.gz /home/your_name/documents Explanation of command: - We create a compressed archive of your documents directory to the directory your currently in called documents.tar.gz
- Use the tar command to use the tar archiving utility
- With the following options -zcvf
- z = compress the archive through gzip
- c = create a new archive
- v = verbose which means list the progress while creating the archive
- f = use archive file
How to extract the compressed archive Use this command: tar -zxvf documents.tar.gz Explanation of command: - Will extract all files in current directory
- Use the tar command to use the tar archiving utility
- With the following options -zxvf
- z = compress the archive through gzip
- x = extract files from an archive
- v = verbose which means list the progress while creating the archive
- f = use archive file
|