Lecture 2 - Linux Command Line Tutorial - cd & pwd commands with their flags explained

Опубликовано: 23 Март 2026
на канале: TechVikings
39
3

in this video we learn about cd & pwd commands with their flags explained


1. pwd
The pwd command stands for Print Working Directory. It shows the full path of the current directory.
Basic Usage:
pwd
Explanation:
• This shows the absolute path of the directory you are in.
• Example:
/home/user/documents
________________________________________
Flags for pwd
-L (Logical Path):
pwd -L
Explanation:
• This shows the logical path, which respects any symbolic links.
• Example: If you’re in a symbolic link to a directory:
/home/user/symlink_folder
• The -L flag will print the path as seen logically, including the symlink.
-P (Physical Path):
pwd -P
Explanation:
• This shows the physical path, resolving any symbolic links.
• Example: Even if you’re in a symbolic link, it will show the actual directory path:
/home/user/real_folder
________________________________________

Practical Demo:
1. Create a directory and a symbolic link:

mkdir real_folder
ln -s real_folder symlink_folder
cd symlink_folder
2. Run pwd:
pwd
o It may show: /home/user/symlink_folder.
3. Use pwd -P to see the physical path:
pwd -P
o It shows: /home/user/real_folder.
________________________________________
2. cd
The cd command stands for Change Directory. It is used to navigate between directories.
Basic Usage:
cd /path/to/directory
Explanation:
• This changes your current directory to the specified path.
• Example:
cd /home/user/documents
pwd
Output:
/home/user/documents
________________________________________
Flags for cd
cd - (Switch to Previous Directory):
cd -
Explanation:
• This switches you back to the previous directory.
• Practical Example:
cd /home/user/documents
cd /home/user/downloads
cd -
Output:
/home/user/documents
cd ~ (Move to Home Directory):
cd ~
Explanation:
• This takes you directly to your home directory.
________________________________________
cd .. (Move Up One Level):
cd ..
Explanation:
• Moves you up one level in the directory structure.
• Example:
o If you’re in /home/user/documents, running cd .. will take you to /home/user.
________________________________________
Logical vs Physical with cd
When using symbolic links:
• Logical (-L): cd respects symbolic links (default behavior).
• Physical (-P): Resolves symbolic links to the real directory.
Example:
cd -P symlink_folder
pwd
• This shows the actual physical path.