Linux cd command

|

What is the cd Command in Linux?

The cd command is used to change the current directory and move from one location to another in Linux. You can use a relative path or an absolute path to navigate between folders.

There are two types of directories:

  1. User-Created Directory: A directory created by the user using the mkdir command in the terminal.
  2. System Directory: A directory already provided by the Linux system, such as root (/), home, and other default directories.

With the cd command, you can move into a new folder, go back to the parent folder, or directly access a system directory.

Syntax:

cd [directory_name or path]

Example 1: Move into a Folder Within the Current Directory (Using a Relative Path)

cd Documents
  • You can enter a folder within your current directory (using a relative path).

Example 2: Move to a Subfolder Inside Documents (Relative Path)

cd Documents/Projects
  • After executing this command, you can move from the present folder into the Projects folder inside Documents.

Example 3: Go Back to the Previous Directory

cd ..
  • Takes you one step back from your current location.

Example 4: Go Directly to the Home Directory

cd ~
  • It brings you to your user’s home folder.

Example 5: Move Using an Absolute Path

cd /home/user/Desktop
  • Moves directly to the Desktop folder from anywhere.

ONLINE WEB TOOLS

WhatIsMyIpAddress
Shorterner