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:
Go to a specific directory (absolute path): If you know the full path to a directory, you can go there directly.
cd /home/labex/projectThis command would take you directly to the
/home/labex/projectdirectory, regardless of where you currently are.Go to a specific directory (relative path): You can navigate using paths relative to your current working directory.
- If you are in
/home/labexand you want to go into theprojectdirectory (which is insidelabex):cd project - If you are in
/home/labex/projectand you want to go into a subdirectory calledmy_files:cd my_files
- If you are in
Go up one level (parent directory): The
..(double-dot) represents the parent directory.- If you are in
/home/labex/projectand want to go back to/home/labex:cd ..
- If you are in
Go back to your home directory: There are a few ways to quickly return to your home directory:
- Using
~(tilde):cd ~ - Simply typing
cdwithout any arguments:cd
Both of these commands will take you to your home directory, which for you is
/home/labex.- Using
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.