0
0
Linux CLIscripting~10 mins

tar (create and extract archives) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - tar (create and extract archives)
Start
Choose Action
Create Archive
Run tar with -c
Archive Created
End
The flow shows choosing to create or extract an archive using tar, running the command, then finishing.
Execution Sample
Linux CLI
tar -cvf archive.tar file1.txt file2.txt

tar -xvf archive.tar
First command creates an archive named archive.tar with two files; second command extracts files from archive.tar.
Execution Table
StepCommandActionOutputResult
1tar -cvf archive.tar file1.txt file2.txtCreate archive named archive.tarfile1.txt file2.txtarchive.tar created with 2 files
2tar -xvf archive.tarExtract files from archive.tarfile1.txt file2.txtfile1.txt and file2.txt extracted
3EndNo more commandsProcess complete
💡 All files archived and extracted successfully, process ends.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
archive.tardoes not existcreated with file1.txt and file2.txtexistsexists
file1.txtexistsexistsexistsexists
file2.txtexistsexistsexistsexists
Key Moments - 3 Insights
Why do we use -c to create and -x to extract?
The -c option tells tar to create an archive (see Step 1 in execution_table), while -x tells tar to extract files from an archive (see Step 2). Using the wrong option will not perform the intended action.
What does the -v option do?
The -v option makes tar show the files being processed (visible in Output column in Steps 1 and 2). It helps you see progress but is optional.
Why specify the archive file name after -f?
The -f option tells tar the name of the archive file to create or extract. Without it, tar uses a default or errors out. This is shown in the Command column in Steps 1 and 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table Step 1. What does the output show?
AThe names of files added to the archive
BThe contents of the archive file
CAn error message
DThe size of the archive
💡 Hint
Check the Output column in Step 1 showing file1.txt and file2.txt
At which step are files extracted from the archive?
AStep 1
BStep 2
CStep 3
DNone
💡 Hint
Look at the Action column for Step 2 in execution_table
If we omit the -v option, what changes in the output?
AThe archive is not created
BFiles are not extracted
CNo file names are shown during create or extract
DThe archive file name changes
💡 Hint
Compare Output columns in Steps 1 and 2; -v controls verbosity
Concept Snapshot
tar command creates or extracts archives.
Use -c to create, -x to extract.
Use -f to specify archive file name.
-v shows files being processed.
Example: tar -cvf archive.tar files
Example: tar -xvf archive.tar
Full Transcript
This lesson shows how to use the tar command to create and extract archive files. First, you choose whether to create or extract. To create, use tar with -c (create), -v (verbose), and -f (file) options, followed by the archive name and files to include. The command lists files as it adds them. To extract, use tar with -x (extract), -v, and -f options, followed by the archive name. The command lists files as it extracts them. The process ends when all files are archived or extracted. Key points: -c creates, -x extracts, -v shows progress, -f names the archive file. This helps you bundle files into one archive or unpack them easily.