How do I navigate between directories?

QuestionsQuestions8 SkillsProDec, 17 2025
0105

That's a very important question for working in Linux!

To navigate between directories, you use the cd command, which stands for "change directory".

Here are some common ways to use cd:

  1. Go to a specific directory (absolute path):
    If you know the full path to a directory, you can go there directly.

    cd /home/labex/project

    This command would take you directly to the /home/labex/project directory, regardless of where you currently are.

  2. Go to a specific directory (relative path):
    You can navigate using paths relative to your current working directory.

    • If you are in /home/labex and you want to go into the project directory (which is inside labex):
      cd project
    • If you are in /home/labex/project and you want to go into a subdirectory called my_files:
      cd my_files
  3. Go up one level (parent directory):
    The .. (double-dot) represents the parent directory.

    • If you are in /home/labex/project and want to go back to /home/labex:
      cd ..
  4. Go back to your home directory:
    There are a few ways to quickly return to your home directory:

    • Using ~ (tilde):
      cd ~
    • Simply typing cd without any arguments:
      cd

    Both of these commands will take you to your home directory, which for you is /home/labex.

  5. Go to the previous directory you were in:
    The - (hyphen) character can take you back to your last working directory.

    cd -

    This is very handy for toggling between two frequently used directories.

Before you cd:
It's often helpful to use ls first to see the contents of your current directory and identify the directories you might want to enter.

Example workflow:

pwd             # Let's say you are in /home/labex/project
ls              # See what's inside /home/labex/project
cd ..           # Go up to /home/labex
pwd             # Now you are in /home/labex
cd project      # Go back down into project
pwd             # Now you are in /home/labex/project

Feel free to try these commands out! Let me know if you would like me to guide you through an example.

0 Comments

no data
Be the first to share your comment!