Module lessons (2/2)
Moving around the file system (cd)
To move from one folder to another in the Linux file system, use the command:
cd [path]This command stands for Change Directory. The path of the folder you want to enter can be specified in two ways: using an absolute path or a relative path.
Absolute vs Relative Paths
-
Absolute Path: Always starts from the root
/and describes the entire path to the destination.- Example:
cd /home/user/documents - No matter which folder you are currently in, an absolute path will always direct you to the same place.
- Example:
-
Relative Path: Starts from your current directory.
- Example: If you are already in
/home/user, to enter/home/user/documentsyou only need to typecd documents(without a forward slash/at the beginning).
- Example: If you are already in
Special Shortcuts
Linux provides several useful shortcuts to navigate quickly:
.(single dot): Represents the current directory...(double dot): Represents the parent directory (one level up in the directory tree).- Example: If you are in
/home/user/documents, typingcd ..will take you up to/home/user.
- Example: If you are in
~(tilde): Represents your home directory (/home/user). Typingcd ~(or simplycdwith no arguments) will instantly return you home.
Navigation Examples and Common Errors
If you try to access a directory that does not exist, the terminal will show you an error like this:
cd nonexistent_folder
# Output:
# cd: nonexistent_folder: No such file or directoryYou can chain navigation or use pwd to verify the effect of changing folders:
cd documents
pwd
# Output:
# /home/user/documentsTry it yourself
Exercise 1: Enter a folder
Move inside the 'documents' directory using a relative path.
Show hint
Use the cd command followed by the name of the destination folder.
Solution available after 3 attempts
Exercise 2: Go up one level
Move back to the parent directory relative to your current location.
Show hint
Use cd followed by the special shortcut for the parent folder.
Solution available after 3 attempts
Exercise 3: Return Home
Move inside the 'documents' directory and immediately after return to your home directory using the ~ special shortcut.
Show hint
First use cd followed by documents, then use cd followed by ~.
Solution available after 3 attempts