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) or C:\ (Windows).
  • Example path: /Users/username/Documents.

Using relative paths

  • Start with current directory.
  • Don't begin path with / or C:\.
  • 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

  1. Open your terminal.
  2. View your current location.
  3. List the contents of the current directory.
  4. Navigate to your home directory.
  5. Create a new directory (mkdir Foldername).
  6. Move into the newly created directory.
  7. Go back to home directory.
  8. Test out tab completion.

Common mistakes

  1. Slashes: Different operating systems use different slashes in the path:
    • Windows: \ or /
    • macOS/Linux: /
  2. Case sensitivity: Watch for case sensitive file/folder names:
    • Windows: Not case-sensitive
    • macOS/Linux: Case-sensitive
    • Documents is documents on macOS/Linux
  3. Spaces: Use quotes or escape when spaces are used:
    • Quotes: cd "My Documents"
    • Or escape spaces: cd My\ Documents