0
0
Linux CLIscripting~15 mins

tar (create and extract archives) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Using tar to Create and Extract Archives
📖 Scenario: You have a folder with some important files. You want to bundle them into one archive file to save space or share easily. Later, you want to open that archive to get the files back.
🎯 Goal: Learn how to use the tar command to create an archive file from multiple files and then extract the files back from the archive.
📋 What You'll Learn
Create a tar archive from multiple files
Use a variable to store the archive file name
Extract files from the tar archive
Display the list of files extracted
💡 Why This Matters
🌍 Real World
Archiving files into a single file helps in backup, sharing, and saving disk space. The tar command is widely used in Linux systems for these tasks.
💼 Career
Knowing how to create and extract tar archives is essential for system administrators, developers, and anyone working with Linux servers or managing files efficiently.
Progress0 / 4 steps
1
Create sample files
Create three empty files named file1.txt, file2.txt, and file3.txt using the touch command.
Linux CLI
Need a hint?

Use touch followed by the file names separated by spaces.

2
Set archive file name variable
Create a variable called archive_name and set it to myfiles.tar.
Linux CLI
Need a hint?

Use archive_name=myfiles.tar without spaces around the equals sign.

3
Create the tar archive
Use the tar command with options -cf to create an archive named by $archive_name containing file1.txt, file2.txt, and file3.txt.
Linux CLI
Need a hint?

Use tar -cf $archive_name file1.txt file2.txt file3.txt to create the archive.

4
Extract and list files from the archive
Use the tar command with options -xf to extract files from $archive_name. Then use ls to list the extracted files.
Linux CLI
Need a hint?

Use tar -xf $archive_name to extract and ls file1.txt file2.txt file3.txt to list the files.