Navigating the File System

Navigating the File System

Linux File Navigation

Core Navigation Commands

1. pwd - Print Working Directory

Shows your current location in the file system:

pwd

Output: /home/username

2. ls - List Files and Directories

List contents of the current directory:

ls

Useful ls Options:

ls -l      # Long format with details
ls -a      # Show hidden files (starting with .)
ls -la     # Long format + hidden files
ls -h      # Human-readable file sizes
ls -R      # Recursive (include subdirectories)

Understanding ls -l Output:

drwxr-xr-x  2 username username 4096 Feb 15 10:30 Documents
PartMeaning
dDirectory (folder)
rwxr-xr-xPermissions
2Number of links
usernameOwner
usernameGroup
4096Size in bytes
Feb 15 10:30Last modified
DocumentsName

3. cd - Change Directory

Navigate between directories:

cd /home              # Go to /home directory
cd ..                # Go up one level
cd ../..             # Go up two levels
cd ~                 # Go to home directory
cd -                 # Go back to previous directory

Path Types:

  • Absolute path: Starts from root / (e.g., /home/username/Documents)
  • Relative path: Starts from current directory (e.g., Documents or ./Documents)

File and Directory Operations

4. mkdir - Make Directory

Create new directories:

mkdir myfolder              # Create single directory
mkdir -p folder/subfolder   # Create nested directories
mkdir -p project/{src,bin,docs}  # Multiple directories

5. rmdir - Remove Directory

Delete empty directories:

rmdir myfolder

6. rm - Remove Files

Delete files:

rm myfile.txt              # Delete single file
rm -r myfolder             # Delete folder and contents
rm -rf myfolder            # Force delete (no prompt)

Be careful with rm -rf! There's no trash bin in Linux.

7. cp - Copy Files

Copy files and directories:

cp file.txt backup.txt           # Copy file
cp -r folder/ backup/            # Copy folder
cp *.txt destination/             # Copy all .txt files

8. mv - Move/Rename Files

Move or rename files:

mv oldname.txt newname.txt       # Rename
mv file.txt /path/to/destination/  # Move

Viewing File Contents

9. cat - Display File Contents

cat myfile.txt

10. head and tail - View Part of File

head -n 10 myfile.txt    # First 10 lines
tail -n 10 myfile.txt    # Last 10 lines

11. less - View File Page by Page

less myfile.txt

Press q to quit, arrow keys to navigate.

Practical Examples

Example: Organize Your Projects

cd ~
mkdir -p projects/{website,scripts,notes}
cd projects/website
touch index.html style.css script.js
ls

Summary

Master these navigation commands to efficiently work in Linux:

  • pwd - Where am I?
  • ls - What's here?
  • cd - Go there
  • mkdir - Create folder
  • cp - Copy
  • mv - Move/Rename
  • rm - Delete

Next Lesson

In the next lesson, you'll learn how to access your Windows files from Linux using the /mnt directory.

Quiz - Quiz - Navigating the File System

1. Which command shows your current directory?

2. What does 'cd ..' command do?

3. Which command creates a new directory?

4. What does 'ls -la' show?

5. Which command copies a file?

First Launch and Ubuntu Basics