Basic Commands
Now you have your terminal ready, let's learn the basic commands for navigating your computers file system.
Understanding your location
Show current directory
You can find your current location/directory using the Print Working Directory command:
pwd
This command shows the full path to your current directory. For example:
- Windows:
C:\Users\YourName\Documents
- macOS/Linux:
/Users/YourName/Documents
Listing contents
We can also list the contents of the current directory:
# List files and directories
ls
# List with details (date, permissions etc)
ls -l
# List all files (including hidden)
ls -a
Basic navigation
Changing directories
To change the directory, use the cd
command:
# Change to a directory by name
cd directory_name
# Move to home directory
cd ~
# or simply
cd
# Move up one directory/level
cd ..
# Move up multiple directories
cd ../..
# Move to previous directory
cd -
💡 Tip: Some terminals allow using the Tab key to autocomplete the directory name.
Special directories
/
- Root directory~
- Home directory.
- Current directory..
- Parent directory
Path types
Using absolute paths
- Start with root directory.
- Begin with
/
(macOS/Linux) orC:\
(Windows). - Example path:
/Users/username/Documents
.
Using relative paths
- Start with current directory.
- Don't begin path with
/
orC:\
. - Example:
Documents/Homework
.
Useful tips
Auto complete
- Use the
Tab
kep to auto-complete file/directory names. - Press
Tab
twice cycle through possible options.
History
- Up arrow: Previous command
- Down arrow: Next command
Ctrl + R
: Search history
Clearing the screen
# Clear the terminal screen/lines above
clear
# or
Ctrl + L
Practice exercise
- Open your terminal.
- View your current location.
- List the contents of the current directory.
- Navigate to your home directory.
- Create a new directory (
mkdir Foldername
). - Move into the newly created directory.
- Go back to home directory.
- Test out tab completion.
Common mistakes
- Slashes: Different operating systems use different slashes in the path:
- Windows:
\
or/
- macOS/Linux:
/
- Windows:
- Case sensitivity: Watch for case sensitive file/folder names:
- Windows: Not case-sensitive
- macOS/Linux: Case-sensitive
Documents
isdocuments
on macOS/Linux
- Spaces: Use quotes or escape when spaces are used:
- Quotes:
cd "My Documents"
- Or escape spaces:
cd My\ Documents
- Quotes: