Log in from a computer to take this course

You'll need to log in from a computer to start Introduction to Linux. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Archiving allows us to consolidate multiple files or directories into a single archived file. Two of the popular archive commands on Linux, zip and tar, have the ability to compress and archive files. This means that unlike the compression commands which compress a single file at a time, the files’ size will be reduced and packaged into a single archive file in one command.

zip

Zip files are very popular across multiple operating systems. We can create a .zip archive like so:

zip <archive_name>.zip <file1> <file2> …

Note: On some distributions of Linux, zip must first be installed using the command sudo apt install zip unzip.

Directories can be easily archived with the -r option. Archived files can be extracted and decompressed using the unzip command and providing paths to one or more .zipfiles.

tar

tar, which stands for tape archive or tarball, is a very important archiving utility for Linux systems. While a zip archive is more popular across platforms, it is recommended to use tar when distributing archives among Linux-based systems. This is because tar archives store Unix file attributes, retaining file permissions and other metadata.

tar -cf <archive_name>.tar <files or directories>

creates a uncompressed .tar archive. A .tar file can be referred to as a tarball.

For example,

tar -cd example.tar index.html script.js style.css

will create a .tar archive file with three files: index.html, script.js, and style.css.

To extract the files in a .tar archive, we can use the -xf option.

tar -xf <archive_name>.tar

In the next exercise, we will learn how to further compress .tar files.

Instructions

1.

Run the command ls -R to see all the files in the current directory and subdirectories.

2.

Extract the archive named important.zip.

3.

Create a .zip archive of the riddles directory. At the end, there should be one file called riddles.zip.

4.

Extract the files.tar tarball.

5.

Create a tarball named text_files.tar of the files hello.txt, bye.txt, and poem.txt.

6.

Run the command ls -R again to see the resulting files after using the commands we just learned.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?