Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The cd
command in Linux (short for "change directory") is a built-in shell command used to navigate between directories in the file system. In this tutorial, we will discuss how to use the cd
command effectively, along with various options and examples.
Basic usage of the cd
command:
To change to a specific directory, use the cd
command followed by the path of the directory:
cd /path/to/directory
This command will change the current working directory to the specified directory.
Navigating to the home directory:
To quickly navigate to your home directory, you can use the cd
command without any arguments or with the ~
character:
cd
or
cd ~
Both commands will change the current working directory to your home directory.
Navigating to the parent directory:
To navigate to the parent directory of the current working directory, use the ..
notation:
cd ..
This command will change the current working directory to its parent directory.
Navigating to the previous working directory:
To navigate back to the previous working directory, use the -
character:
cd -
This command will change the current working directory to the previous working directory and display the path of the new working directory.
Navigating using absolute and relative paths:
Absolute paths: An absolute path starts with a /
and represents the full path of the directory. For example:
cd /usr/local/bin
Relative paths: A relative path is a path relative to the current working directory. For example:
cd Documents/Work
This command assumes that there is a Work
directory inside the Documents
directory, which is a subdirectory of the current working directory.
By following this tutorial, you should now have a good understanding of how to use the cd
command in Linux to navigate between directories in the file system. The cd
command is a fundamental command for working with the file system and is essential for efficient command-line navigation.
How to use cd
command in Linux:
cd
command.cd directory_name
Changing directories in the terminal with cd
:
cd /path/to/directory
Navigating the file system using cd
in Linux:
cd
.cd /parent_directory/child_directory
Relative vs. absolute paths with cd
command:
cd
.cd ../relative_directory
Moving up one directory with cd ..
:
cd ..
Using wildcards with cd
in Linux:
cd /path/to/di*rectory
Creating and navigating through directories with cd
:
cd new_directory && mkdir new_directory
cd
command shortcuts and tips:
cd - # Return to the previous directory
Changing to the home directory with cd ~
:
cd ~