Overview
We cover everything you need to know about the cd command, the fundamental core of Linux terminal operations. From navigating with absolute and relative paths to returning to previous directories and jumping to your home directory, explore practical tips and shortcuts to maximize workflow efficiency alongside hands-on examples.
Basic Directory Navigation: Understanding Absolute and Relative Paths
Run the mkdir -p /tmp/cd_practice/project/src command to create the directory hierarchy for practicing the cd command.

The cd command is the standard command used in Linux to change the current working directory.
Specify an absolute path starting from the root (/) directory to navigate directly to your target location.
⚙️ [Key Options]
-L : Retains logical path handling without resolving symbolic links.-P : Resolves symbolic links and moves to the actual physical path.-e : When used with -P, returns a non-zero exit status if unable to determine or navigate to the physical directory.@ : On systems supporting file attributes, navigates while referencing extended attributes.

The pwd command prints the absolute path of the current working directory to the terminal, allowing you to verify the navigation result.

Navigate to the src directory using a relative path, which references a subdirectory directly relative to the current working directory.

Run the pwd command again to confirm that you have successfully navigated to the src subdirectory.

Move one level up to the immediate parent directory using .., the special relative path notation representing the parent directory.

Navigating to the Home Directory and Utilizing the Tilde (~) Operator
The tilde (~) symbol is a special character representing the current logged-in user’s home directory. Use the cd ~ command to jump immediately to the home directory.

Run the pwd command to confirm that the current working directory has correctly changed to /root, the root account’s home directory.

When executed alone without any path arguments, the cd command navigates to the user’s home directory by default.

Run the pwd command once more to verify that executing just cd without arguments also places you in the home directory, /root.

Using the logical operator ||, first attempt to navigate to ~/Desktop. If that fails because the folder does not exist, safely fall back to navigating to the home directory (cd ~).

Returning Instantly to the Previous Working Path with the cd - Shortcut
Run the mkdir -p /tmp/cd_practice/backup command to create a backup directory for practicing path return.

First, navigate to the base directory /tmp/cd_practice/project to prepare for testing navigation to the previous path.

Change your working directory to the newly created /tmp/cd_practice/backup directory.

The cd - command immediately returns to the previous working directory stored in the OLDPWD environment variable.
Upon execution, it prints the destination path to the screen.

Run the pwd command to verify that you have successfully returned to the previous directory, /tmp/cd_practice/project.

Safely Navigating Directories with Spaces and Special Characters
Run the mkdir -p "/tmp/cd_practice/my workspace" command to set up a practice directory containing spaces.

When a directory name contains spaces, wrap the entire path in double quotes (") to ensure the shell safely interprets the path as a single string argument.

Run the pwd command to confirm that you have successfully moved into the working directory containing spaces.

Alternatively, escape the space by placing a backslash (\) immediately before it, telling the shell to treat the space as part of the directory name rather than an argument separator.

We have reviewed the fundamental usage and essential shortcuts for the cd command to ensure fast and efficient directory navigation in Linux environments.
Familiarize yourself with these handy path shortcuts to boost your terminal productivity.