Linux Foundations / Inspect Storage and Restore Owned Files

Inspect capacity, mounts and directory usage

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

A small notes directory can live on a nearly full filesystem. Measuring the notes answers how much that selected tree uses; it does not tell you how much space the containing filesystem has available. Choose the measurement's scope before interpreting its number.

You will create two tiny, supplied notes in an owned guest workspace, inspect their containing mount, and distinguish filesystem capacity, directory usage and block-device size. All storage commands in this lesson are observations. The only changes are the two notes and their named practice directories.

1. Choose the question before the tool

A filesystem organizes files and directories. A mount makes a filesystem or part of one accessible at a path in the directory tree. A block device provides addressable storage, such as a virtual disk, partition or logical volume. These are related concepts, but their sizes and boundaries are not interchangeable. Some mounted filesystems are not backed by a block device.

QuestionToolScope of the answer
How much space does the filesystem containing this path report?dfThe containing filesystem, including data outside this practice tree.
How much usage belongs to this selected directory tree?duThe named directory and its descendants that the command can inspect.
Which mounted filesystem contains this path?findmntThe selected path's mount information.
Which block devices exist, and how are they related?lsblkBlock-device information; device size is not filesystem free space.

A containing filesystem holds the drafts subtree, the separate review subtree and other guest data. The df scope covers the containing filesystem; the du scope selects drafts and its note only. Reported byte units do not imply one-byte allocation units.

Read the outer filesystem boundary separately from the smaller selected directory boundary. The blue arrow connects the whole filesystem to df; the green arrow connects only drafts to its du report. This is an expected scope model to compare with your observations; areas are not to scale and the figure does not supply measured capacity values. The figure includes the review note that you create later during independent practice.

Allocated usage describes storage allocated to objects. Apparent size describes their logical lengths. Small files can consume a whole allocation unit even when their text is shorter. A directory can also contribute its own allocation to ordinary du totals. In the selected GNU Coreutils 9.4, apparent-size du counts regular files and symbolic links rather than directory lengths; this behavior changed in 9.2. This fixture has only ordinary directories and one regular note in each child, so each apparent child total measures that note's logical bytes, including its newlines. A longer note does not guarantee a larger allocated total.

2. Prepare two small, owned directories

Complete the earlier file, shell and process lessons, ending with Send a signal to a verified practice process. Use the ordinary nonzero-UID account in the checked Ubuntu guest, with earlier practice jobs settled. Run one command line at a time, inspect its result, and stop after an unexpected error. No host terminal, privilege elevation, mount change, partition change or large allocation is part of this task.

Reuse the taught identity and command-origin checks:

id -u
id -un
ps -p $ -o comm=
type cd pwd printf set mkdir cat df du findmnt lsblk ls rm rmdir

Require the recorded nonzero account and active Bash. cd, pwd, printf and set must be Bash builtins; the other commands must resolve to their expected guest tools. For a listing alias, use the complete taught check:

type -a ls
type -P ls

Accept only the understood color-only alias, if present, and expected executable paths; stop for a function, other alias behavior or unexpected origin. Preserve accepted configuration. Inspect options without changing them:

set -o

Require errexit off so an expected absent-name observation does not end an altered shell. Reconcile an unexpected baseline instead of changing settings.

The task owns ~/linux-practice/inspect-filesystem-usage/. Reuse ls -ld without trailing slashes to inspect the directory entries themselves:

ls -ld ~
ls -ld ~/linux-practice
ls -ld ~/linux-practice/inspect-filesystem-usage

Require the known ordinary parent directories owned by your account. The exercise name must be absent for a fresh start. Reject links or unrecognized ownership, and use the resume section for an existing attempt. After acceptance:

mkdir ~/linux-practice/inspect-filesystem-usage
ls -ld ~/linux-practice/inspect-filesystem-usage

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

cd ~/linux-practice/inspect-filesystem-usage
pwd
ls -a

Require the recorded shared-root path followed by /inspect-filesystem-usage and only . and ... After that location and inventory check:

mkdir drafts review
ls -ld -- drafts review
ls -a -- drafts
ls -a -- review

Require two ordinary owned empty directories, with no links or unexpected contents. The taught printf '%s\n' writes each supplied string followed by a newline. The taught > creates a fresh output and would replace an existing one, so require drafts/note.txt absent before this creation:

printf '%s\n' 'Draft route: north desk.' 'Owner: course learner.' > drafts/note.txt

Inspect its entry and complete contents:

ls -ld -- drafts/note.txt
cat drafts/note.txt

Require a regular file with one link and your recorded owner, containing exactly these two newline-terminated lines:

Draft route: north desk.
Owner: course learner.

Keep this note unchanged. The review directory stays empty until the independent task. Record observations in your own notes; this exercise does not need redirected capacity reports or extra output files.

3. Identify the containing mount and filesystem capacity

findmnt reads mount information. Its -T option takes a target path and selects the mount containing that path; the path need not itself be a mount point. The . argument means the checked current directory. -o requests the named output columns: TARGET is the mount point, SOURCE identifies the mounted source, and FSTYPE gives the filesystem type.

findmnt -T . -o TARGET,SOURCE,FSTYPE

Read and record all three fields. A target such as / can be correct even though you supplied a path deeper inside your home. The target is the containing mount, not a restatement of the input path. Actual source names, filesystem types and mount points vary with the checked guest installation. Do not replace an observed logical-volume name with a guessed disk name.

df with a path operand reports that path's containing filesystem. -B1 sets its reported size units to one byte; it does not change allocation units or allocate data. The explicit --output list chooses the columns below. The taught -- ends options before the . operand.

df -B1 --output=source,fstype,size,used,avail,pcent,target -- .
Requested fieldInterpretation
source, fstypeReported filesystem source and type; compare with the mount evidence.
sizeReported filesystem capacity in bytes.
usedReported used filesystem space in bytes.
availReported space available to an unprivileged user, in bytes.
pcentReported percentage used, not a byte count.
targetMount point of the reported filesystem.

The displayed headings may differ from these field selector names. Read the values with their headings and record when you observed them. Other guest activity can change available space between observations. Filesystem accounting and reserved space mean used + avail need not equal size; explicit byte units do not remove that distinction.

Predict: if you pass drafts instead of ., should df narrow its scope to the note's text? Explain before testing:

df -B1 --output=source,fstype,size,used,avail,pcent,target -- drafts

For this same-mount fixture it still reports the containing filesystem. Changing the path selects which filesystem to report; it does not turn df into a directory-size tool. Compare source, type and mount point, rather than requiring volatile capacity values to be identical at two moments.

4. Measure the selected subtree in explicit units

du walks a named directory tree and summarizes its usage. Here -s requests one summary for the argument, and -B1 reports allocated usage in bytes. The operand is only the owned drafts subtree:

du -s -B1 -- drafts

Read the number together with its drafts label. It includes the directory and its contained note, not just the file text. Require a complete observation with no read or traversal error. An error can leave a partial result, so a printed number alone is not proof that every object was inspected.

--apparent-size changes the measurement to apparent lengths while keeping the same chosen subtree and -B1 byte units:

du -s --apparent-size -B1 -- drafts

Record both numbers and explain what changed: the measurement, not the directory contents. On the selected GNU 9.4, apparent-size totals count regular files and symbolic links, excluding directory lengths. Because this checked subtree contains just one regular file and no links, this total is the note's logical byte length, including its two newlines. This is a version-specific behavior, not a rule to assume for every older du implementation. Neither command changes allocation or compresses the note.

The filesystem's df used value and the drafts du total have different scopes. Other directories, filesystem accounting, and data outside this selected tree contribute to the difference. These two commands are not an equality test or a complete disk-reconciliation investigation. You do not need to scan /, change permissions, or remove anything to make their numbers match.

5. Keep block-device size separate

lsblk reports block devices. -b displays its size values in bytes, and -o chooses a stable set of columns rather than depending on default output:

lsblk -b -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINTS

NAME identifies the device; tree indentation can show relationships. TYPE distinguishes kinds such as disk, partition or logical volume. SIZE is block-device size in bytes. FSTYPE reports detected filesystem type, and MOUNTPOINTS lists associated mount paths where available. Blank fields are incomplete or inapplicable information, not a reason to format a device.

Compare the output with the containing-mount observation. A disk can have partitions or other layers, and a filesystem can have more than one mount path. A memory-backed mount will not become a physical disk just because findmnt reports it. Do not demand one matching lsblk row for every mount. Explain which observations you can connect and leave unclear relationships unresolved. No device operation is required to finish this read-only step.

Diagnose a measurement before acting

ObservationUseful interpretationSafe next check
df is much larger than the drafts du total.Whole-filesystem and subtree scopes differ.Compare the supplied operands and recorded mount.
Apparent and allocated totals differ.Logical lengths and allocation answer different questions.Keep both in explicit byte units and recheck the exact subtree.
Two small notes produce equal allocated totals.Different text lengths can fit within the same allocation sizes.Check content and apparent measurements; do not create large filler data.
A source or device name differs from an example.Installation layouts and names vary.Record actual findmnt and lsblk fields; do not guess replacements.
du prints an error and a total.Some data may not have been inspected.Recheck known ownership, path and permissions without broad repair.
A required tool is missing or output is incomplete.The checked guest readiness or observation is incomplete.Return to the readiness lesson; preserve disk and mount state.

Independent task: compare two questions about two directories

Keep the guided note unchanged. Recheck the exact working path and both directory identities, then inspect review and require it empty:

pwd
ls -ld -- drafts review
ls -a -- review
cat drafts/note.txt

Only after accepting that evidence, create the distinct four-line note:

printf '%s\n' 'Draft route: north desk.' 'Owner: course learner.' 'Status: ready for review.' 'Keep both notes for comparison.' > review/note.txt

Inspect the new entry and every line:

ls -ld -- review/note.txt
cat review/note.txt

Require a regular owned single-link file containing exactly the four supplied strings, each terminated by a newline. The first two lines match the guided note; the two added lines are part of this separate note only.

Before opening hints or the answer:

  1. Use the taught target-path mount query separately for each child. Establish whether they are within the same mount from the actual fields, rather than assuming it from equal capacity numbers or the directory names.
  2. Compare both children's allocated totals in bytes, then compare their apparent totals in bytes. Predict whether more lines guarantees a larger allocated total, and explain your actual observation without forcing one.
  3. Choose the evidence for each request: “How much space does this selected subtree use?” and “What space does its containing filesystem report as available?” Explain why a block-device SIZE is not the latter answer.
  4. Diagnose the statement “df and du disagree, so delete files until the two numbers match.” Explain its mistaken scope comparison and give an observation that addresses the original capacity question.

Success: both notes retain their exact supplied contents; each mount claim has path-specific evidence; every recorded size has units and scope; and your explanation distinguishes allocation, apparent lengths, filesystem availability and device size. No particular capacity or ordering of the two allocated totals is required.

Graduated hints

  1. -T selects findmnt's containing mount for the following path. Run that observation once per child and compare all requested fields.
  2. Du accepts more than one named operand; -s yields a summary for each. Keep -B1 in both forms so the comparison does not mix units.
  3. --apparent-size changes du's measurement. Passing another directory operand to df still selects a filesystem, not a subtree total.

Answer and Reasoning

From the verified exercise directory, first establish each child's mount:

findmnt -T drafts -o TARGET,SOURCE,FSTYPE
findmnt -T review -o TARGET,SOURCE,FSTYPE

For the intended fresh fixture, both observations should identify the same mount point, source and filesystem type. A different mount observation is evidence that the starting layout differs; stop and reconcile it without mounting, unmounting or moving data to force agreement.

Then compare the two measurements using the same explicit byte units:

du -s -B1 -- drafts review
du -s --apparent-size -B1 -- drafts review

Keep each value paired with its path and measurement name. The first command answers allocated subtree usage; the second answers the logical bytes of the regular notes in these checked one-file subtrees on GNU 9.4, excluding directory lengths. The longer review note has more logical bytes, but need not produce a larger allocated total. Your actual filesystem determines these figures; equal totals, for example, do not imply identical file contents.

For reported filesystem availability, use the containing filesystem query:

df -B1 --output=source,fstype,size,used,avail,pcent,target -- review

The avail column addresses that question for an unprivileged user at the observation time. It covers the filesystem containing review, not spare space reserved for the review directory. A block-device SIZE describes a different layer and does not report available filesystem space.

The proposed deletion “repair” has no valid target condition: df covers a filesystem, while du covered only named child trees. Those numbers are not supposed to be forced equal. Compare the containing mount and df availability to answer the capacity question, while retaining du for the selected-tree question. Recheck both note contents after the read-only observations:

cat drafts/note.txt
cat review/note.txt

Require the original two and four complete lines. Accurate content, units, scope and explained differences provide the evidence; a command returning without an error does not supply that reasoning by itself.

Cleanup after the comparison

Reinspect the known parents and exercise entry without following a link:

ls -ld ~/linux-practice
ls -ld ~/linux-practice/inspect-filesystem-usage

Require the recorded ordinary owned directories, then enter and check separately:

cd ~/linux-practice/inspect-filesystem-usage
pwd

Require the exact recorded exercise path before inspecting the owned children:

ls -a
ls -ld -- drafts review
ls -a -- drafts
ls -a -- review
ls -ld -- drafts/note.txt review/note.txt

Require only the two known child directories and dot entries at the root, and the corresponding known regular, single-link, owned note in each child. Recheck complete contents if any identity is uncertain; leave unknown entries untouched. The shown y/n responses assume English confirmations. Establish the program's documented responses before removal and stop if unsure.

Only after acceptance, use the taught interactive named removal:

rm -i -- drafts/note.txt review/note.txt

Approve only the two recognized files. To stop, decline the current and every remaining prompt; one refusal does not cancel later prompts. Reinspect both child inventories and identities before directory removal:

ls -a -- drafts
ls -a -- review
ls -ld -- drafts review

Only if both recognized owned directories are empty:

rmdir -- drafts review
ls -a

Require only . and .. in the exercise directory. Return to the shared root and verify its path before the separate final removal:

cd ~/linux-practice
pwd

Require the recorded shared-root path, then inspect the exercise entry:

ls -ld -- inspect-filesystem-usage

Only for that recognized owned empty directory:

rmdir -- inspect-filesystem-usage
ls -a

Retain the shared root and other lessons. There is no mount, partition or filesystem configuration to restore because this task did not change it.

Resume a partial attempt

Recheck the normal guest account, command origins, directories and exact location. Inspect each existing child and note. Resume from the last accepted state: two-line drafts note created, mount and usage observations recorded, or four-line review note created. Repeating a read-only query is allowed; record it as a new observation because filesystem usage can change over time.

Do not rerun a > seed command over an existing note. For a recognized incorrect note from this attempt, inspect it, remove only that named file with the taught interactive guard, confirm absence, then recreate the supplied content. For a full restart, remove only the recognized files and empty directories actually created, following the same location and identity gates. Preserve unexplained entries and resolve their identity before proceeding.

Sources and other study views

The selected platform uses Bash 5.2, GNU Coreutils 9.4 and util-linux 2.39.3. The upstream Coreutils reference can describe a newer version; the lesson uses the bounded forms explained here. Actual capacities, source names and mount layouts come from the learner's observations, not a fixed sample image.

Revision reconstructs the scope decisions; Quick Reference retrieves the commands and interpretation guards.

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