cd Command in Linux

Learn via video courses
Topics Covered

Overview

The cd command is used to change the current working directory in Linux. It is a simple and powerful command that is used extensively by Linux users and system administrators. In this article, we will discuss the syntax, options, and various usages of the cd command in Linux.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Linux cd Command Syntax

The syntax for the cd command is as follows:

Where:

  • options: The various options that can be used with the cd command are:

    • -P: Use the physical directory structure instead of following symbolic links.
    • -L: Follow symbolic links.
  • directory: The directory parameter can be in one of the following formats:

    • Change to your home directory: cd
    • Change to a specific directory: cd /path/to/directory
    • Change to the previous directory: cd -

cd Command Options:

  • -P: Use the physical directory structure instead of following symbolic links.
  • -L: Follow symbolic links.

Example Usages

  • Change to your home directory::

    Explanation: This command will change your current working directory to your home directory.

  • Change to a specific directory::

    Explanation: This command will change your current working directory to the directory located at /path/to/directory.

  • Change to the previous directory::

    Explanation: This command will change your current working directory to the previous directory you were in.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Tips

  • Use the 'ls' command to list the contents of the directory you are currently in.

  • Use the 'cd ..' command to move up one level in the directory structure.

  • Use the 'cd ~user' command to change to the home directory of another user.

Advanced Use Cases of cd Command in Linux

Conclusion

  • The cd command is a simple and powerful tool for changing the current working directory in Linux.

  • By using the various options and formats, you can customize the behavior of the command to suit your needs.

  • Always be careful when using the cd command, as changing directories can have unintended consequences.

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more