Linux Foundations / Inspect Storage and Restore Owned Files

Archive and restore a small owned file set

Lesson 26 of 37. Open to read. No account needed.

An archive command can succeed while collecting the wrong files. A compressed file can pass an integrity check while still omitting the note you needed. Useful restoration evidence connects the intended source names and contents to the archive's members and then to files restored in a separate directory.

You will archive two supplied workshop notes, list the exact members before extracting, and compare every restored line with the retained originals. Then you will archive and restore one requested subset without including the other note. Everything stays inside one owned guest workspace.

1. Separate packaging, compression and restoration

An archive packages file members and associated metadata into one file. Tar creates, lists and extracts that package. Compression encodes a data stream in a form that can later be decompressed; gzip is the compression program used here. A .tar.gz name is a convention for a gzip-compressed tar archive. The command options choose the behavior; the filename alone does not prove that behavior occurred.

An archive member name is the path recorded inside the archive. We will store agenda.txt and workshop notes.txt, both relative names without a source/ prefix. When extracted beneath a fresh restore directory, those members become files directly inside that destination.

The owned source contains agenda.txt and workshop notes.txt. Both become relative regular-file members in workshop-all.tar.gz outside source. Compression and member-list checks precede extraction into a fresh empty restore-all directory. Every restored line is compared with the retained original files before cleanup.

Follow the green create/extract/compare arrows. The blue retained-source branch keeps the originals as the separate comparison reference for all text and newline counts. Each check answers a different question. This diagram is the expected guided workflow, not evidence that an archive has already been created or restored. It does not show the independent subset's solution.

EvidenceWhat it establishesWhat it does not establish alone
Successful creationThe command completed without a reported failure.The intended file set and content were chosen.
Gzip integrity checkThe compressed stream passes gzip's test.Correct member names, trusted origin or a complete requested file set.
Tar listingRecorded member names and, with verbose output, types.That extracted file contents match the intended originals.
Restored inventory and complete content comparisonThe requested names and text survived this bounded restore.A complete production backup or preservation of every possible metadata feature.

2. Check the normal guest and tool defaults

Complete Compare symbolic and hard links first. Use the ordinary nonzero-UID account in the checked Ubuntu guest, with Bash and the course's GNU tar 1.35/gzip 1.12 tool families. No host terminal, package changes, privilege elevation or outside archive is needed. Run one line at a time, read each result and stop after an unexpected error.

Reuse the taught identity and origin checks before invoking the tools:

id -u
id -un
ps -p $ -o comm=
type cd pwd printf set declare mkdir cat wc tar gzip ls rm rmdir

Require the recorded nonzero account and active Bash. cd, pwd, printf, set and declare must be Bash builtins; the other commands must resolve to expected guest executables. For the listing alias, reuse the complete inspection:

type -a ls
type -P ls

Accept only the understood color-only alias, if present, and expected executable paths. Stop for hidden functions, other alias behavior or an unexpected origin. Inspect options without changing them:

set -o

Require errexit off so the expected absent-declaration observations below can be interpreted without ending an altered shell. Preserve a different setting and reconcile the baseline instead of changing it here.

TAR_OPTIONS and GZIP can supply default options when inherited by their programs. Reuse the taught read-only declare -p inspection for these exact names before any tar or gzip invocation:

declare -p TAR_OPTIONS
declare -p GZIP

For each name, require the expected not-found result: no declaration exists in this practice shell. A declared empty value also differs from this course condition. An unexported local variable is not automatically inherited by an external command; requiring all declarations absent is the deliberately simple course baseline. Do not unset or overwrite an existing declaration to force agreement. Preserve it and reconcile the practice environment.

3. Supply the exact two-file source

The task owns ~/linux-practice/archive-and-restore-owned-files/. Inspect parents and the prospective exercise entry without trailing slashes:

ls -ld ~
ls -ld ~/linux-practice
ls -ld ~/linux-practice/archive-and-restore-owned-files

Require known ordinary parent directories owned by your account, with no links or unexplained identity. The exercise name must be absent for a fresh start; use the resume section for an existing attempt. After acceptance:

mkdir ~/linux-practice/archive-and-restore-owned-files
ls -ld ~/linux-practice/archive-and-restore-owned-files

Require the recognized new ordinary owned directory, then enter separately:

cd ~/linux-practice/archive-and-restore-owned-files
pwd
ls -a

Require the recorded shared-root path followed by /archive-and-restore-owned-files, and only . and ... After that check:

mkdir source
ls -ld -- source
ls -a -- source

Require an ordinary owned empty source directory. Use the taught printf and fresh-output redirection for the first absent filename:

printf '%s\n' 'Workshop: map reading.' 'Start: 10:00.' > source/agenda.txt

Inspect the saved file before creating another:

ls -ld -- source/agenda.txt
cat source/agenda.txt
ls -a -- source

Require an ordinary owned single-link file containing exactly:

Workshop: map reading.
Start: 10:00.

Confirm source/workshop notes.txt absent before the second creation. The quotes keep its space inside one pathname argument:

printf '%s\n' 'Bring a paper map.' 'Work in pairs.' > 'source/workshop notes.txt'

Inspect the second entry and complete contents:

ls -ld -- 'source/workshop notes.txt'
cat 'source/workshop notes.txt'
ls -a -- source

Require another ordinary owned single-link file containing exactly:

Bring a paper map.
Work in pairs.

Each supplied line ends in a newline. The source inventory must contain only these two files plus dot entries, with no links, subdirectories or unexpected names. Keep both originals unchanged through all restore comparisons.

The intended guided member list is therefore:

agenda.txt
workshop notes.txt

Both members must occur once and be regular files. This small explicit list is the manifest: the names and content requirements used to judge the archive and restored result. It is supplied here, not a hidden generated file.

4. Create one compressed archive outside source

Explain the selected tar options before combining them:

OptionMeaning in this lesson
-cCreate an archive.
-tList members without extracting them.
-xExtract members from an archive.
-f FILEUse this explicit archive file; the next argument is its name.
-zUse gzip compression or decompression for the archive stream.
-C DIRChange tar's directory for following member lookup or extraction. It does not change the parent shell's working directory.
-vShow verbose member information, including type, during the listing used below.

Choose one main operation, create/list/extract, per invocation. The options are written separately so each value is easy to identify. The taught -- ends option parsing before the explicitly selected member names.

We will create workshop-all.tar.gz in the checked outer exercise directory, outside source. Tar opens this relative -f archive there; -C source changes where the following member operands are found, not where the parent shell stands. Therefore the archive cannot include itself and the stored names do not acquire an unwanted source prefix.

Recheck the outer pwd, source entry, exact two-file inventory and both complete texts. Inspect the outer ls -a and require workshop-all.tar.gz absent. Tar opens its archive output itself: shell redirection protections do not make an existing archive a safe destination. Only after all checks:

tar -c -z -f workshop-all.tar.gz -C source -- agenda.txt 'workshop notes.txt'
printf 'create status: %s\n' "$?"

Require status 0 and no unexpected diagnostic. Read $? immediately; another command would replace it. A failure can leave a partial archive. Do not continue toward extraction after a failure or assume that an output file proves creation was complete.

Inspect the newly created archive entry before reading it:

ls -ld -- workshop-all.tar.gz

Require the recognized ordinary owned single-link archive created by this attempt. The source files remain in place because this command packages them without removing them.

5. Test compression and list before extraction

gzip -t FILE tests compressed-stream integrity without extracting a file to disk or replacing the archive. Its -t belongs to gzip; tar's -t lists archive members. Neither is a restored-content comparison.

gzip -t -- workshop-all.tar.gz
printf 'gzip test status: %s\n' "$?"

For the intended archive, expect status 0 with no unexpected diagnostic. Gzip uses 1 for an error and 2 for a warning; either is a stop-and-diagnose result for this exercise. A passed compression test does not prove origin, the requested member set or original text completeness.

Now list the archive without extraction:

tar -t -z -f workshop-all.tar.gz
printf 'list status: %s\n' "$?"

Require status 0 and exactly the two relative member names from the manifest, each once. Display quoting of a space can vary; identify the actual workshop notes.txt name as one member. Reject unexpected prefixes, absolute names, parent components such as .., duplicates or extra members. Do not strip or rewrite surprising names and proceed.

Use the explained verbose option to inspect member types. In this GNU verbose listing, the mode/type field must begin with - for each required regular file. A d, l, h or unexplained type is outside this fixture:

tar -t -v -z -f workshop-all.tar.gz
printf 'verbose list status: %s\n' "$?"

Require status 0 and two entries with the explained - regular-file indicator and those same exact names. Ownership, timestamps and display spacing are observations, not fixed sample values. There must be no link, directory or other unexpected member type. This check applies to the archive you just created from the known source; inspecting an arbitrary outside archive is not an authorized substitute for that starting state.

Predict: will extraction create restore-all/source/agenda.txt or restore-all/agenda.txt? Use the stored member name, rather than the original source's full path, to explain your answer before extracting.

6. Restore to a new empty destination and compare every line

Inspect the outer inventory and require restore-all absent. Only after that check create the new destination:

mkdir restore-all
ls -ld -- restore-all
ls -a -- restore-all

Require an ordinary owned directory containing only . and ... Recheck the outer working path and the archive's recognized regular-file identity. Proceed only with the passed compression/list/type checks and this empty destination. Tar can overwrite existing extraction paths, so an old restore directory is not an acceptable shortcut.

tar -x -z -f workshop-all.tar.gz -C restore-all
printf 'extract status: %s\n' "$?"

Require status 0 and no unexpected diagnostic. -C restore-all selects the extraction root; it does not change your shell's current directory. The two stored names should appear directly under that root, without an extra source directory. Inspect the entire result before calling it restored:

ls -a -- restore-all
ls -ld -- restore-all/agenda.txt 'restore-all/workshop notes.txt'
cat source/agenda.txt
cat restore-all/agenda.txt
cat 'source/workshop notes.txt'
cat 'restore-all/workshop notes.txt'

Reuse the taught wc -l to count newline characters in all four files. With multiple operands it also prints their total. These counts complement the complete visible text comparison; they do not prove which words were saved:

wc -l -- source/agenda.txt 'source/workshop notes.txt' restore-all/agenda.txt 'restore-all/workshop notes.txt'

Require two newline characters per file and total 8. Also require exactly two ordinary owned single-link restored files and no other entries beyond dot entries. Compare every line of each original/restored pair with the supplied text. Both agenda reads must contain the two agenda lines; both note reads must contain the two workshop-note lines, with their newlines. Recheck the source inventory and preserve it unchanged.

The successful tar status was one check. Correct member names, file types, restored location and complete content now support the actual outcome. This task does not claim to preserve every possible ownership, permission, extended attribute, application state or backup-recovery requirement.

Diagnose a mismatch while keeping the originals

ObservationUseful distinctionSafe next step
An archive exists after a failed creation.A partial output is not a completed archive.Preserve source; inspect the known output before any scoped rebuild.
Gzip passes but a requested file is absent from the listing.Compression integrity does not validate selection.Compare the exact member operands with the manifest.
Listing contains source/ prefixes.The creation root or selected operands differ.Explain the -C/member relationship before rebuilding a fresh archive.
A member is absolute, contains parent components, is a link or is unexplained.The archive violates this known regular-file contract.Stop before extraction; do not rewrite the archive to bypass the mismatch.
Restored names are correct but text differs.A name-list check did not prove captured contents.Compare full originals and the source state at creation.
Extraction was interrupted.Some members may have appeared while others did not.Keep originals and archive; inspect the partial destination before choosing a scoped reset.

Independent task: restore only the requested note

Keep the full archive, both source files and the complete guided restore unchanged. Recheck the normal shell baseline, exact outer path, source identity/inventory and complete two-line contents. Require these new names absent: workshop-subset.tar.gz and restore-subset.

The new request is specific: archive and restore only workshop notes.txt. Do not include agenda.txt, a source directory member or extra nesting. Before opening the hints or answer:

  1. Create the separate compressed subset archive outside source using an explicit member operand and the taught source root.
  2. Check creation status, archive identity, gzip integrity, exact member listing and regular-file type before extracting anything.
  3. Create a new empty restore-subset directory and extract beneath it.
  4. Verify the requested filename and both exact lines. Explicitly check that agenda.txt and any source/ directory are excluded, not merely that the requested note happens to exist.
  5. Explain why a successful create command followed by a gzip integrity pass would still be insufficient to accept this requested subset.

Success: restore-subset contains exactly one ordinary owned file, workshop notes.txt, with the two supplied workshop-note lines. Both source files and the full restored pair remain unchanged; the subset listing contains only the requested relative regular-file member. The excluded names matter.

Graduated hints

  1. Selection happens through the member operands following -C source. Passing the source directory itself would select a different scope.
  2. Keep the space inside one quoted member name, and keep the archive output outside source with its distinct fresh name.
  3. Reuse create → compression test → list/type check → fresh empty restore → complete content/inventory comparison. The subset has one member, not two.

Answer and Reasoning

From the verified outer exercise directory, with the original source checked and the subset archive name confirmed absent:

tar -c -z -f workshop-subset.tar.gz -C source -- 'workshop notes.txt'
printf 'subset create status: %s\n' "$?"

Require status 0 without unexpected diagnostics. Inspect the archive entry before reading it:

ls -ld -- workshop-subset.tar.gz

Require the recognized regular owned single-link archive, then test it:

gzip -t -- workshop-subset.tar.gz
printf 'subset gzip status: %s\n' "$?"

Require status 0. Inspect the exact member and its type in separate checks:

tar -t -z -f workshop-subset.tar.gz
printf 'subset list status: %s\n' "$?"

Require status 0 and only workshop notes.txt, once, without source/ nesting. Then inspect the verbose listing:

tar -t -v -z -f workshop-subset.tar.gz
printf 'subset verbose status: %s\n' "$?"

Require status 0 and exactly one regular-file member with that relative name. If any condition differs, stop before extraction and diagnose selection. Recheck the outer inventory and require restore-subset absent before:

mkdir restore-subset
ls -ld -- restore-subset
ls -a -- restore-subset

Require the new ordinary owned empty directory, the checked outer working path and the same recognized archive. Only then extract:

tar -x -z -f workshop-subset.tar.gz -C restore-subset
printf 'subset extract status: %s\n' "$?"

Require status 0, then inspect both included and excluded names through the complete destination inventory:

ls -a -- restore-subset
ls -ld -- 'restore-subset/workshop notes.txt'
cat 'restore-subset/workshop notes.txt'
cat 'source/workshop notes.txt'
cat source/agenda.txt
ls -a -- source
ls -a -- restore-all
cat restore-all/agenda.txt
cat 'restore-all/workshop notes.txt'

Check the newline counts for both sources and all three restored files, using the same taught count as the guided comparison:

wc -l -- source/agenda.txt 'source/workshop notes.txt' restore-all/agenda.txt 'restore-all/workshop notes.txt' 'restore-subset/workshop notes.txt'

Require two newlines in every file and total 10, together with the complete text comparisons. Require the restored note to be an ordinary owned single-link file. Restore-subset must have only that known note plus dot entries: no agenda.txt, no source directory and no extra names. Its two lines must be Bring a paper map. and Work in pairs., each newline-terminated. Check the full guided restore and both originals against their original two-line texts as well.

The explicit member operand selected one file even though the source directory still contains two. -C source made that member relative to source during creation; -C restore-subset placed the same stored name under a different root during extraction. The shell remained in the outer exercise directory.

A valid compressed stream could contain two files, one wrong file or an old version of the right file. That is why successful creation and gzip testing cannot establish the subset requirement without exact member and restored content checks. Exclusion is part of the requirement, not an optional cleanup.

Cleanup after both restore comparisons

Keep originals until every required comparison is complete. Reinspect the known shared and exercise entries without trailing slashes:

ls -ld ~/linux-practice
ls -ld ~/linux-practice/archive-and-restore-owned-files

Require ordinary directories owned by your recorded account, then enter and verify separately:

cd ~/linux-practice/archive-and-restore-owned-files
pwd

Require the exact recorded exercise path before the inventory/identity checks:

ls -a
ls -ld -- source restore-all restore-subset
ls -a -- source
ls -a -- restore-all
ls -a -- restore-subset
ls -ld -- source/agenda.txt 'source/workshop notes.txt' restore-all/agenda.txt 'restore-all/workshop notes.txt' 'restore-subset/workshop notes.txt' workshop-all.tar.gz workshop-subset.tar.gz

Require only the known three ordinary owned directories, two owned regular archives and five regular single-link text files in their expected places. Recheck any uncertain text against the manifest; preserve unknown entries. Archives must be the outputs created and checked in this attempt, not files borrowed from elsewhere.

The shown y/n responses assume English confirmations. Establish the actual program's documented responses before removal and stop if unclear. Remove only the named archive outputs first:

rm -i -- workshop-all.tar.gz workshop-subset.tar.gz

Approve only recognized targets. To stop, decline the current and every remaining prompt; one refusal does not cancel later prompts. Require those archive names absent after inspecting the outer inventory. Then remove only the verified restored text copies:

rm -i -- restore-all/agenda.txt 'restore-all/workshop notes.txt' 'restore-subset/workshop notes.txt'

Honor every refusal and recheck the restore inventories. Once both restore directories are confirmed empty and still the known ordinary owned entries:

rmdir -- restore-all restore-subset

Only after the comparisons are complete and the originals are still identified as the two supplied text files, remove those named sources:

rm -i -- source/agenda.txt 'source/workshop notes.txt'

Reinspect source identity and inventory:

ls -ld -- source
ls -a -- source

Only when that recognized directory is empty:

rmdir -- source
ls -a

Require the exercise directory empty, then return and inspect separately:

cd ~/linux-practice
pwd

Require the recorded shared-root path and inspect the exercise entry again:

ls -ld -- archive-and-restore-owned-files

Only for that same recognized owned empty directory:

rmdir -- archive-and-restore-owned-files

Retain the shared root, other lessons, tar/gzip packages and all preexisting shell settings. This task created no tool-default declarations to unset.

Resume without overwriting the evidence

Recheck account, Bash, origins, absent tool-default declarations, owned directory identities and exact location. Inspect the actual source and outputs to identify whether source creation, full-archive checks, guided restore or subset work last completed. Keep the originals until the corresponding restore's full comparison passes.

Do not rerun seed redirection over a note, tar creation over an existing archive, or extraction into a partial restore directory. Tar opens its own output files; a familiar filename is not an overwrite permission.

For an interrupted or failed archive, preserve the checked source and inspect the recognized partial archive. Remove only that named owned output with the taught interactive guard, confirm it absent, then rebuild and repeat all checks. For a partial extraction, inventory the owned restore directory and remove only the recognized named text files actually present, followed by its empty directory. Confirm the destination absent, create it freshly, then extract only after the archive checks pass again.

If unexpected members or unexplained files appear, leave them untouched and reconcile the mismatch. Do not use broad recursive removal to make a restore look clean. A full restart uses the same guarded named cleanup for only this attempt's known files and empty directories.

Sources and other study views

The selected guest baseline uses GNU tar 1.35 and gzip 1.12. The Bookworm tar companion is 1.34; it supports the longstanding options used here and does not replace the selected-version reference. The upstream Coreutils manual may describe a newer release than the course's 9.4 utility baseline.

Revision reconstructs the evidence chain; Quick Reference retrieves commands after the full procedure.

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy