Linux Foundations / Work With Files and Paths

Navigate absolute and relative paths

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

A pathname tells the shell or a program where to look. Some paths carry their starting point with them; others depend on where you are now. If you confuse those forms, the same directory name can lead to a different place or no place at all. Checking the current directory before acting makes the difference visible.

You will create two empty directories inside one owned guest exercise, reach them in several ways, and predict each resulting location. After an independent navigation task, you will remove only the named empty exercise directories. The shared practice root and other lessons' work remain available.

Starting state and boundaries

Complete Find the right help for a command first. Use the ordinary Bash account in the checked vecta-lab-linux guest. This lesson creates only ~/linux-practice/navigate-paths/ and its children drafts and archive. The parent ~/linux-practice/ may already exist from setup. No input download, account change or administrator permission is needed.

The already taught id -u check must show a nonzero user ID. Record the username from id -un for the ownership checks below, and ps -p $ -o comm= must identify Bash. type inspects names before use; confirm cd and pwd are the expected Bash builtins and mkdir and rmdir are the distribution's external utilities. An unexplained alias, function or location is a setup question to resolve before changing files.

id -u
id -un
ps -p $ -o comm=
type cd pwd mkdir rmdir

We use ls to inspect directories. Preserve the ordinary listing setup from the previous lesson, including any understood color alias. If its origin is unclear, repeat that lesson's lookup before using it. Commands in this lesson run in the guest; the host terminal is not an alternative execution location.

Name the starting points

TermMeaning
Filesystem root, /The top of the guest's pathname hierarchy. The initial slash in an absolute path starts here.
Your home directoryThe directory assigned to your ordinary account, normally beneath /home in this guest. Observe its actual path instead of guessing your username.
Current working directoryThe directory your shell is working from now. A relative path begins here.
Parent directory, ..The directory one level above the current path position.
Current-directory entry, .The current path position itself.

The filesystem root / is not the root user. Inspecting a root-based path does not make your ordinary account an administrator. The conventional /root directory is the root account's home; it is not your ordinary account's home.

pwd prints the current working directory. cd changes the current directory of this shell. In cd ~, an unquoted leading ~ is expanded by Bash to your home directory. It is a home-based shortcut, not another name for /.

cd ~
pwd

Record that actual absolute home path in your notes. An illustrative result is /home/mira; your account name may differ. Do not copy mira into your commands unless it is actually your account. Keep ~ unquoted in the home shortcuts shown here so Bash performs the intended expansion.

The filesystem also has shared system directories. ls / lists the root's entries without moving your shell there or modifying them:

ls /
pwd

Your pwd result should still be the recorded home path. Some names you may recognize have different purposes:

Guest pathGeneral purpose
/homeHomes of ordinary users under the usual layout
/etcSystem configuration
/usrMuch of the installed user-space software and related files
/varData that changes as system services and applications operate

These names are orientation, not exercise targets. Create the supplied tree under your home; do not create or remove anything in those system directories.

Create a small tree you can account for

Before creating or reusing an existing path, inspect the path itself. ls -l shows a detailed record, including a type/permission field and owner. -d makes ls describe the named directory entry rather than list its contents. Together, ls -ld lets you check a directory's own identity. Use the exact names shown without a trailing slash, so a link is not treated as a request to inspect its destination.

The first character of the type/permission field must be d for a directory, not l for a symbolic link or - for an ordinary file. In the ordinary long listing used here, the owner is the third field, after the type/permission field and link count; the group follows it. That owner must match the ordinary username you recorded with id -un. Leave a link, unexpected file type or unrecognized owner unchanged and reconcile it before proceeding. An ordinary contents listing alone does not establish those facts.

ls -ld ~
ls -ld ~/linux-practice

Your home must be the recognized ordinary directory. If the shared practice parent exists, require that same directory/owner check. If only that parent is reported missing, it may be created below; a different access or inspection error is not permission to continue.

mkdir creates directories. mkdir -p is used only for the shared practice parent: it creates that parent if missing and accepts the checked parent if already present. After an error-free result, inspect the created or retained entry again:

mkdir -p ~/linux-practice
ls -ld ~/linux-practice

Only when that entry is the expected owned directory, enter it and inspect the actual path:

cd ~/linux-practice
pwd

Require the recorded home path followed by /linux-practice. Record that verified result as the shared practice-root path for the final cleanup check. If cd failed or pwd differs, stop here; do not create the exercise from an assumed location.

For the exercise itself, inspect any existing entry before attempting a fresh creation. A missing-name diagnostic is the expected fresh-start observation:

ls -ld ~/linux-practice/navigate-paths

If it exists, inspect its type/owner and follow the resume section rather than rerun the fresh-start commands. A link or unrecognized owner means stop. When the entry is confirmed absent, create only this exercise name:

mkdir ~/linux-practice/navigate-paths
ls -ld ~/linux-practice/navigate-paths

Continue only after an error-free creation and the expected owned directory record. Then enter it and check the actual location and contents:

cd ~/linux-practice/navigate-paths
pwd
ls -a

ls -a includes entries beginning with a dot. Require the recorded shared root followed by /navigate-paths, with only . and .. in the fresh directory. A failed change or other contents means stop the fresh-start sequence and inspect the state. Do not continue creating children in an unrecognized place.

The next mkdir receives two relative names. Because you just checked the current directory, both new children belong to this one exercise:

mkdir drafts archive
ls -ld drafts archive
ls -a
ls -a drafts
ls -a archive

Both detailed child records must show d and your recorded ordinary owner. The parent listing should contain drafts and archive in addition to its dot entries. Each child listing should contain only . and ... This establishes the complete input fixture: two known empty directories, with no files hidden inside them. Display order can differ; names and relationships are the checks.

Read the path map

The guest filesystem root leads through the ordinary account's home and linux-practice to the navigate-paths exercise. Its drafts and archive directories are siblings. With drafts as the current directory, ../archive goes through the parent to archive; an absolute path starts at root and a tilde-based path starts at home.

Read the hierarchy from the filesystem root toward the two children. The relative arrow begins at drafts, the current directory in that scene; it goes up to the exercise parent and down to archive. The absolute route begins at /; the ~ route begins at the account's home after Bash expands the shortcut. Each route's starting point is part of its meaning. All paths shown belong to the guest filesystem.

Here are the three forms for the archive target:

FormStarting pointInterpretation
/home/mira/linux-practice/navigate-paths/archiveFilesystem rootIllustrative absolute path; substitute your recorded actual home path.
~/linux-practice/navigate-paths/archiveYour home after Bash expands the leading tildeReaches this account's exercise without depending on the current directory.
../archiveCurrent directory, when it is draftsMove up one level, then enter the sibling archive.

The leading slash is decisive: home/mira without the slash would be a relative path from the current directory, not the root-based /home/mira. The names in a path are separated by /; those separators do not all mean “start over from root.” It is the initial slash that establishes an absolute starting point.

This fixture contains ordinary directories, not symbolic links. Later storage lessons discuss links; do not generalize this simple parent-path exercise to an unexplained linked directory elsewhere on the system.

Guided navigation: predict, move, inspect

Your goal is to reach the same known tree using different starting points. Before each cd, write the expected complete pwd result in your notes, using your actual home prefix. Only then run the group and compare. No navigation command below creates, copies or moves a directory; it changes this shell's current location.

From home to a child with a relative path

First make the starting directory explicit:

cd ~
pwd

From that home, the relative path begins with the child linux-practice:

cd linux-practice/navigate-paths/drafts
pwd
ls -a

The expected location is your home path followed by /linux-practice/navigate-paths/drafts. Its listing should still be empty apart from . and ... The path worked because you began at home; starting with the same relative words from inside drafts would ask for a different, nonexistent descendant in this fixture.

From one sibling to the other

You are now in drafts. In ../archive, .. first selects the exercise parent; archive then selects a child of that parent. Predict the result:

cd ../archive
pwd
ls -a

You should be in your exercise's archive, with the same empty listing. Record this actual pwd output as the full absolute archive path. It will be the supplied input for the next comparison, so you need not invent a username.

Reach the same target with its observed absolute path

Return home, which gives you a different starting directory:

cd ~
pwd

Now type cd, one space, and the exact absolute archive path you recorded, then press Enter. The following is an illustrative example, not a path to paste with someone else's account name:

cd /home/mira/linux-practice/navigate-paths/archive

After entering your own complete command, inspect the result:

pwd
ls -a

The location should match the earlier archive path exactly. This route did not depend on beginning in drafts or home; the leading slash supplied its starting point. If the result differs, stop and compare the exact input with the recorded path before another move.

Use the home shortcut and the parent entry

The leading unquoted ~ selects your home even from archive. Use it to reach drafts again, then inspect what moving to the parent does:

cd ~/linux-practice/navigate-paths/drafts
pwd
cd ..
pwd

The two pwd results should end in /navigate-paths/drafts, then /navigate-paths. cd .. did not mean “go home”; it meant go up one level from that current directory. A second .. would start from the new position, which is why tracking each successful step matters.

Diagnose a path that does not lead where you expect

ObservationEvidence to inspect and safe response
A relative path reports “No such file or directory”Run pwd, then list the current directory with ls -a. If appropriate, ls -a .. reads the parent without changing location. Compare where the path starts with where its first name actually exists.
A failed cd leaves the prompt looking similarCheck pwd. A failed change does not put you at the requested destination; do not continue as if it did.
An absolute example fails under another usernameUse the actual home/archive path you observed. Do not create someone else's path to make the example work.
mkdir reports an existing exercise or childInspect it and use the resume branch; do not broadly delete or overwrite it.
An unexpected permission error appearsCheck the ordinary account and exact guest path. Administrator permission does not correct a wrong relative starting point.
The current path is outside the owned exerciseNavigate explicitly to the known home-based exercise path, inspect it, and reassess before any creation or cleanup.

Predict from this state: while in drafts, does the relative path archive name its sibling? No: it would name a child inside drafts. The sibling route needs the parent step first. You do not need to create a mistaken extra child to prove that distinction.

Independent task: reverse the sibling route

Keep both empty children until this task and its checks are complete. Establish the supplied starting directory with the home shortcut:

cd ~/linux-practice/navigate-paths/archive
pwd

From archive, do the following without reading the answer yet:

  1. Write the expected complete pwd result for drafts, using your actual home path. Reach it with one relative path; do not start that path with / or ~.
  2. Inspect the actual location and empty contents. Explain which component selected the parent and which selected the sibling.
  3. Write your expected home pwd result, return home with the taught shortcut, and inspect it. Explain why this return does not depend on how deep the current directory was.
  4. Compare the roles of /, ~, . and ... Identify which one needs the current path position to interpret the parent step.

Success is matching your predictions with the actual locations and explaining the starting points. Copying a path without being able to name its starting point is an incomplete check. No automatic score is produced.

Hints

Hint 1 — use the sibling relationship: archive and drafts have the same parent. Going directly to drafts without a parent step would ask for a child of your current archive directory.

Hint 2 — combine two steps in one path: the first component can be ... Follow it with / and the sibling's actual name.

Hint 3 — keep home separate from parent: the already taught cd ~ returns to the account's home from either child. cd .. moves only one level up.

Answer and Reasoning

With the verified starting location in archive, the relative route is:

cd ../drafts
pwd
ls -a

.. selects navigate-paths; drafts selects that parent's other child. The resulting path is your observed home followed by /linux-practice/navigate-paths/drafts. The listing still has only . and .., because navigation changes the shell's location, not directory contents.

Return home and inspect it:

cd ~
pwd

The result must match the home path recorded at the beginning. Bash's leading tilde expansion supplies that home path regardless of the current depth. The filesystem root / supplies an absolute starting point; . is the current position; .. is its parent. A relative path such as ../drafts is meaningful only with its starting directory known.

The guided absolute route used the actual path printed while you were in archive. That observation supplied the account-specific input, and the leading slash made the next lookup begin at root. The home shortcut reaches the same account's tree without embedding an example username. Both can reach the target from another current directory, but the tilde form first depends on Bash expanding the home shortcut.

Cleanup after the independent task

The previous help lesson established the condition for rmdir: it removes directories only when they are empty, with normal access checks still applying. Here you will use it for the first time on the two directories you just created. -- ends option parsing; the following names are the exact directory operands. There is no recursive removal and no wildcard in this cleanup.

First inspect the shared root and exercise entry itself, without trailing slashes. Require the recorded ordinary directory types and ownership before entering either path:

ls -ld ~/linux-practice
ls -ld ~/linux-practice/navigate-paths

Then enter the exercise and check the location:

cd ~/linux-practice/navigate-paths
pwd

Require exactly the recorded shared-root path followed by /navigate-paths. A failed cd or different result means stop before any relative cleanup. With that location established, inspect each child itself as well as its contents:

ls -ld drafts archive
ls -a
ls -a drafts
ls -a archive

Each child must be the known owned directory (d, not l) and contain only . and ... Unknown types, ownership or contents mean leave it untouched.

Only after the independent work is complete and those checks agree, remove the two named empty children, then verify the remaining parent is empty:

rmdir -- drafts archive
ls -a

Return to the shared practice root. Remove only the now-empty exercise parent, and retain the shared root plus every other lesson directory:

cd ~/linux-practice
pwd

Require pwd to match the recorded shared practice-root path exactly. If cd failed or the location differs, stop before the next block. Recheck that the exercise entry is still the known owned directory, then remove it only while it remains empty:

ls -ld navigate-paths

Require the known directory type and ordinary owner again. Only with those checks and its confirmed emptiness satisfied:

rmdir -- navigate-paths
ls -a

Success is that this exercise name is gone and ~/linux-practice/ still exists with any other work intact. If rmdir reports a nonempty directory, stop and inspect it rather than using a stronger deletion command. When multiple names are supplied, an earlier empty target may already have been removed before a later target fails; inspect the actual remaining names before retrying.

Resume without guessing

If navigate-paths already exists, first use ls -ld on the exact shared parent and exercise paths without trailing slashes, and require directory records owned by your ordinary account. Inspect existing drafts and archive entries the same way before following them or listing their contents. Only then use pwd and the exact home-based path to resume. If it contains only the two known empty children from this exercise, keep them and resume navigation. If a known child was never created or was already cleaned up, create only that missing name with the taught mkdir after verifying the parent. Do not rerun a multi-name creation blindly and ignore a partial result.

Unknown files, unexpected directories or links are not this lesson's supplied empty fixture. Leave them intact and reconcile their origin before claiming a fresh start or applying cleanup. After successful cleanup, you can recreate the fresh tree with the documented steps when you want to repeat the task.

Technical references

Use Revision to reconstruct the starting points and Quick Reference for the taught path and cleanup patterns.

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