Essential Linux Navigation Commands: ls, pwd, cd, whoami for LFCS Certification

Master essential Linux navigation commands for LFCS. Learn whoami, pwd, cd shortcuts (cd ~, cd -, cd ..), ls options (-a, -l, -al), understand ls -l output format, and build command-line confidence with 20+ practice labs.

29 min read

Welcome to Part 7 of the LFCS Certification - Phase 1 series! You've learned how Linux commands work with case sensitivity and options. Now it's time to master the essential navigation commands that you'll use hundreds of times every day as a Linux system administrator.

๐Ÿ’ก

๐ŸŽฏ What You'll Learn: In this comprehensive guide, you'll master:

  • whoami - Identifying who you are logged in as
  • pwd - Finding your current directory location
  • cd - Changing directories with powerful shortcuts
  • cd ~ - Quick jump to home directory
  • cd - - Toggle between two directories
  • cd .. - Move up to parent directory
  • ls - List directory contents
  • ls -a - Show hidden files (dotfiles)
  • ls -l - Long format with detailed information
  • ls -al - Combining options for complete view
  • Understanding every field in ls -l output
  • File permissions, ownership, timestamps, and sizes
  • 20+ comprehensive practice labs

Series: LFCS Certification Preparation - Phase 1 (Post 7 of 52) Previous: Part 6 - Linux Command Basics (Case Sensitivity and Options) Next: Part 8 - Understanding File Timestamps with touch

Introduction: Why Navigation Commands Matter

Before you can manage files, configure services, or troubleshoot systems, you need to know where you are and what's there. These four commands form the foundation of Linux navigation:

  • whoami - Know your identity (which user you are)
  • pwd - Know your location (which directory you're in)
  • cd - Change your location (move between directories)
  • ls - See what's around you (list files and directories)

Think of these as your compass, GPS, vehicle, and binoculars in the Linux filesystem. Let's master each one.

whoami: Identifying Your Current User

What is whoami?

The whoami command prints your current effective user ID. In other words, it tells you who the system thinks you are right now.

๐Ÿ’ก

๐Ÿ’ก Why This Matters: When switching between users with su or sudo -i, it's easy to forget which user you're currently operating as. One wrong command as root could be catastrophic. Always verify with whoami.

Basic whoami Usage

[centos9@centos ~]$ whoami
centos9

What happened:

  • Command: whoami
  • Output: centos9
  • This tells us we're currently logged in as the centos9 user

whoami vs id Command

The whoami command is actually equivalent to id -un:

[centos9@centos ~]$ whoami --help
Usage: whoami [OPTION]...
Print the user name associated with the current effective user ID.
Same as id -un.

      --help     display this help and exit
      --version  output version information and exit

Key point: whoami only shows your username. For more detailed information (UID, GID, groups), use the id command instead.

Real-World whoami Scenarios

Scenario 1: After using su

[centos9@centos ~]$ whoami
centos9

[centos9@centos ~]$ su -
Password:
[root@centos ~]# whoami
root

Scenario 2: Verification before dangerous operations

[root@centos ~]# whoami
root

[root@centos ~]# rm -rf /old-backups/*
# Knowing you're root is critical before running destructive commands!

pwd: Print Working Directory

What is pwd?

The pwd command prints the full absolute path of your current working directory. It answers the question: "Where am I right now in the filesystem?"

Understanding Directories (A Quick Refresher)

In Linux:

  • / is the root directory (top of the filesystem tree)
  • Every other directory is nested under /
  • Your current location is called the working directory or current directory

Basic pwd Usage

[centos9@centos ~]$ pwd
/home/centos9

What happened:

  • Command: pwd
  • Output: /home/centos9
  • This is the full path from root (/) to your current location

The Tilde (~) Symbol

Notice the prompt shows ~ instead of /home/centos9:

[centos9@centos ~]$ pwd
/home/centos9

The ~ symbol is a shortcut for your home directory:

  • For user centos9: ~ = /home/centos9
  • For user ubuntu: ~ = /home/ubuntu
  • For root: ~ = /root

pwd After Changing Directories

[centos9@centos ~]$ pwd
/home/centos9

[centos9@centos ~]$ cd /var/log

[centos9@centos log]$ pwd
/var/log

What happened:

  1. Started in /home/centos9 (home directory)
  2. Changed to /var/log directory
  3. Confirmed new location with pwd

Notice how the prompt changed from ~ to log - the prompt shows your current directory name.

cd: Change Directory

The cd command is how you navigate the Linux filesystem. It's one of the most frequently used commands you'll encounter.

Basic cd Syntax

cd [directory]

Absolute vs Relative Paths

Absolute path - Starts from root (/):

[centos9@centos ~]$ cd /var/log
[centos9@centos log]$ pwd
/var/log

Relative path - Relative to current location:

[centos9@centos log]$ cd systemd
[centos9@centos systemd]$ pwd
/var/log/systemd

cd Without Arguments: Go Home

Running cd with no arguments takes you to your home directory:

[centos9@centos log]$ pwd
/var/log

[centos9@centos log]$ cd

[centos9@centos ~]$ pwd
/home/centos9
๐Ÿ’ก

๐Ÿ’ก Pro Tip: cd with no arguments is the fastest way to return home. You'll use this constantly!

cd ~: Explicit Home Directory

Using cd ~ is equivalent to cd with no arguments:

[centos9@centos ~]$ cd /var/log
[centos9@centos log]$ pwd
/var/log

[centos9@centos log]$ cd ~
[centos9@centos ~]$ pwd
/home/centos9

Both commands do the same thing:

  • cd โ†’ go to home directory
  • cd ~ โ†’ go to home directory

cd ..: Parent Directory

Use cd .. to move up one level to the parent directory:

[centos9@centos ~]$ cd /var/log/systemd
[centos9@centos systemd]$ pwd
/var/log/systemd

[centos9@centos systemd]$ cd ..
[centos9@centos log]$ pwd
/var/log

[centos9@centos log]$ cd ..
[centos9@centos var]$ pwd
/var

Understanding ..:

  • . (single dot) = current directory
  • .. (double dot) = parent directory
  • cd .. moves you up one level in the directory tree

You can chain multiple levels:

[centos9@centos ~]$ cd /var/log/systemd
[centos9@centos systemd]$ cd ../../etc
[centos9@centos etc]$ pwd
/etc

What happened:

  • Started in /var/log/systemd
  • ../.. went up two levels to /var
  • /etc went from /var to /etc

cd -: Previous Directory

This is one of the most useful cd shortcuts! Use cd - to toggle between your current and previous directory:

[centos9@centos ~]$ cd /var/log
[centos9@centos log]$ pwd
/var/log

[centos9@centos log]$ cd ~
[centos9@centos ~]$ pwd
/home/centos9

[centos9@centos ~]$ cd -
/var/log
[centos9@centos log]$ pwd
/var/log

[centos9@centos log]$ cd -
/home/centos9
[centos9@centos ~]$ pwd
/home/centos9

What happened:

  1. Changed to /var/log
  2. Went back to home (~)
  3. Used cd - to go back to /var/log
  4. Used cd - again to return to /home/centos9
โš ๏ธ

โš ๏ธ Common Mistake: Don't confuse cd - (previous directory) with cd .. (parent directory). They're completely different!

  • cd - = "Go to the directory I was just in"
  • cd .. = "Go up one level"

cd Command Summary Table

CommandWhat It DoesExample
cdGo to home directorycd
cd ~Go to home directory (explicit)cd ~
cd /pathGo to specific absolute pathcd /var/log
cd ..Go to parent directory (up one level)cd ..
cd ../..Go up two levelscd ../..
cd -Go to previous directory (toggle)cd -
cd ./subdirGo to subdirectory (relative path)cd ./Documents

ls: List Directory Contents

The ls command lists files and directories. It's probably the most frequently used Linux command after cd.

Basic ls Usage

[centos9@centos ~]$ ls
aws-owais-io-credentials  blog  claude-api  Coursera  cron_output.txt
Desktop  Documents  Downloads  file_list.txt  Music  names.txt
owais-io  Pictures  Public  Razzaq-Labs-II  ss.sh  temp-cv
Templates  test.txt  token  Videos

What happened:

  • Command: ls
  • Output: All visible files and directories in the current directory
  • Files and directories are displayed in columns
๐Ÿ’ก

๐Ÿ’ก Notice: Some names are in color (if your terminal supports it):

  • Blue = directories
  • White = regular files
  • Green = executable files
  • Red = archives (zip, tar, etc.)
  • Cyan = symbolic links

ls -a: Show Hidden Files

In Linux, files starting with a dot (.) are hidden by default. Use ls -a to show all files including hidden ones:

[centos9@centos ~]$ ls -a
.                         .bash_profile  .claude.json         .docker
..                        .bashrc        .claude.json.backup  Documents
.aws                      blog           .config              Downloads
aws-owais-io-credentials  .cache         Coursera             .gitconfig
.bash_history             claude-api     cron_output.txt      .lesshst
.bash_logout              .claude        Desktop              Music

What happened:

  • -a flag means "all"
  • Now we see hidden files (dotfiles): .bash_history, .bashrc, .gitconfig, etc.
  • We also see . and ..:
    • . = current directory
    • .. = parent directory

Why hidden files matter:

  • Configuration files are usually hidden: .bashrc, .ssh/, .gitconfig
  • User preferences and application data: .mozilla, .config
  • Shell history: .bash_history
  • As a system administrator, you'll frequently work with hidden files

ls -l: Long Format (Detailed View)

The -l option shows detailed information about each file:

[centos9@centos ~]$ ls -l
total 5936
drwxr-xr-x.  2 centos9 centos9      40 Oct 10 18:24 aws-owais-io-credentials
drwxr-xr-x. 11 centos9 centos9    4096 Oct 29 18:15 blog
-rw-r--r--.  1 centos9 centos9     109 Sep 15 00:14 claude-api
drwxr-xr-x.  3 centos9 centos9      21 Oct 31 14:59 Coursera
-rw-r--r--.  1 centos9 centos9     930 Oct  4 02:04 cron_output.txt
drwxr-xr-x.  2 centos9 centos9    4096 Oct 15 16:45 Desktop
drwxr-xr-x.  2 centos9 centos9       6 Jul 20 15:36 Documents
-rw-r--r--.  1 centos9 centos9    1077 Oct  1 13:11 file_list.txt
-rwxr-xr-x.  1 centos9 centos9      69 Jul 29 13:17 ss.sh
-rw-r--r--.  1 centos9 centos9 6044864 Jul 31 15:41 test.txt

This output contains a wealth of information! Let's break down every field.

Understanding ls -l Output (Critical for LFCS!)

Let's analyze one line in detail:

-rw-r--r--.  1 centos9 centos9    1077 Oct  1 13:11 file_list.txt

Field-by-field breakdown:

FieldValueMeaning
1. File Type-Regular file (- = file, d = directory, l = link)
2. Permissionsrw-r--r--Owner: read+write, Group: read, Others: read
3. SELinux Context.Has SELinux context (RedHat/CentOS feature)
4. Hard Links1Number of hard links (usually 1 for files)
5. Ownercentos9User who owns the file
6. Groupcentos9Group that owns the file
7. Size1077File size in bytes
8. TimestampOct 1 13:11Last modification date and time
9. Filenamefile_list.txtName of the file

File Type Indicators

The first character tells you what type of entry it is:

CharacterTypeExample
-Regular file-rw-r--r-- file.txt
dDirectorydrwxr-xr-x Desktop
lSymbolic linklrwxrwxrwx link โ†’ target
bBlock devicebrw-rw---- sda
cCharacter devicecrw-rw-rw- tty
sSocketsrwxr-xr-x socket
pNamed pipe (FIFO)prw-r--r-- pipe

Permission Breakdown

The next 9 characters show permissions in three groups of three:

rw-r--r--
โ”‚โ”‚โ”‚โ”‚โ”‚โ”‚โ”‚โ”‚โ”‚
โ”‚โ”‚โ”‚โ””โ”ดโ”ดโ”ดโ”ดโ”ดโ”€ Others permissions (r--) = read only
โ”‚โ””โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€ Group permissions (r--) = read only
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Owner permissions (rw-) = read + write

Each group has three possible permissions:

  • r = read (4)
  • w = write (2)
  • x = execute (1)
  • - = permission not granted

Example breakdown:

-rwxr-xr-x.  1 centos9 centos9  69 Jul 29 13:17 ss.sh
 โ”‚โ”‚โ”‚ โ”‚โ”‚โ”‚ โ”‚โ”‚โ”‚
 โ”‚โ”‚โ”‚ โ”‚โ”‚โ”‚ โ””โ”ดโ”ดโ”€ Others: r-x (read + execute) = 5
 โ”‚โ”‚โ”‚ โ””โ”ดโ”ดโ”€โ”€โ”€โ”€โ”€ Group:  r-x (read + execute) = 5
 โ””โ”ดโ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Owner:  rwx (read + write + execute) = 7

This file has permissions 755 (rwxr-xr-x):

  • Owner can read, write, and execute
  • Group can read and execute
  • Others can read and execute
๐Ÿ’ก

๐Ÿ’ก Coming Up: We'll cover permissions in depth in a future post. For now, just understand how to read them in ls -l output.

Directory vs File in ls -l

Compare these two entries:

# Regular file
-rw-r--r--.  1 centos9 centos9     109 Sep 15 00:14 claude-api

# Directory
drwxr-xr-x.  2 centos9 centos9    4096 Oct 15 16:45 Desktop

Key differences:

  1. File type: - (file) vs d (directory)
  2. Permissions: Files rarely need execute (x), directories always need it to enter
  3. Size: Directories show block size (usually 4096), not content size

ls -al: Combining Options

You can combine -a (all files) and -l (long format):

[centos9@centos ~]$ ls -al
total 6196
drwx------. 30 centos9 centos9    4096 Oct 31 14:59 .
drwxr-xr-x.  5 root    root         52 Oct  6 18:20 ..
drwxr-xr-x.  2 centos9 centos9      39 Oct 17 02:04 .aws
-rw-------.  1 centos9 centos9   23413 Oct 30 13:10 .bash_history
-rw-r--r--.  1 centos9 centos9      18 Feb 15  2024 .bash_logout
-rw-r--r--.  1 centos9 centos9     141 Feb 15  2024 .bash_profile
-rw-r--r--.  1 centos9 centos9     752 Oct  6 16:35 .bashrc
drwxr-xr-x. 11 centos9 centos9    4096 Oct 29 18:15 blog
-rw-r--r--.  1 centos9 centos9      61 Jul 20 20:20 .gitconfig
-rw-------.  1 centos9 centos9      56 Oct 30 13:05 .lesshst

What we see now:

  • All files including hidden dotfiles
  • Detailed information for each entry
  • Notice .bash_history has permissions rw------- (owner only - good for security!)
  • Configuration files like .bashrc and .bash_profile

Other Useful ls Options

OptionWhat It DoesExample
-hHuman-readable sizes (KB, MB, GB)ls -lh
-tSort by modification time (newest first)ls -lt
-rReverse sort orderls -ltr
-SSort by file size (largest first)ls -lS
-RRecursive (list subdirectories too)ls -R
-dList directory itself, not contentsls -ld /var
-iShow inode numbersls -li

Pro combination for sysadmins:

ls -laht

This shows:

  • -l = long format
  • -a = all files (including hidden)
  • -h = human-readable sizes
  • -t = sorted by time (newest first)

Perfect for checking recent changes in a directory!

๐Ÿงช Practice Labs

Now let's put everything together with comprehensive hands-on practice!

Lab 1: Basic Navigation and Verification (Beginner)

Tasks:

  1. Check which user you're logged in as
  2. Find out what directory you're currently in
  3. List all files in your current directory
  4. Navigate to /etc and verify you're there
  5. Return to your home directory
  6. List files in /var/log without changing directory
Click to reveal solution
# Task 1: Check current user
whoami

# Task 2: Check current directory
pwd

# Task 3: List files
ls

# Task 4: Navigate to /etc and verify
cd /etc
pwd

# Task 5: Return home
cd
pwd

# Task 6: List files in /var/log without moving
ls /var/log

Lab 2: Working with Hidden Files (Beginner)

Tasks:

  1. List all files including hidden ones in your home directory
  2. Find and view the .bashrc file (just check if it exists)
  3. Count how many hidden files are in your home directory
  4. List all hidden files that start with .bash
  5. Check if you have a .ssh directory
Click to reveal solution
# Task 1: List all files including hidden
cd ~
ls -a

# Task 2: Check for .bashrc
ls -a | grep bashrc
# Or simply:
ls -la .bashrc

# Task 3: Count hidden files
ls -a | grep "^\." | wc -l

# Task 4: List .bash* files
ls -a .bash*

# Task 5: Check for .ssh directory
ls -ld .ssh
# Or:
ls -a | grep "^\.ssh$"

Lab 3: Understanding ls -l Output (Intermediate)

Tasks:

  1. List /etc/passwd in long format
  2. Identify: file type, permissions, owner, group, size, timestamp
  3. Find the largest file in your home directory
  4. Find the most recently modified file in /etc
  5. List /tmp showing human-readable sizes
Click to reveal solution
# Task 1: Long format for /etc/passwd
ls -l /etc/passwd

# Example output analysis:
# -rw-r--r--. 1 root root 2847 Oct 31 15:00 /etc/passwd
# Type: - (regular file)
# Permissions: rw-r--r-- (644)
# Owner: root
# Group: root
# Size: 2847 bytes
# Timestamp: Oct 31 15:00
# Name: passwd

# Task 3: Find largest file in home
ls -lSh ~

# Task 4: Most recently modified in /etc
ls -lt /etc | head -5

# Task 5: Human-readable sizes in /tmp
ls -lh /tmp

Lab 4: Directory Navigation Shortcuts (Intermediate)

Tasks:

  1. Go to /var/log/ and then jump back to home using cd shortcut
  2. From home, go to /usr/share/doc, then back home, then toggle back using cd -
  3. Navigate from home to /var/log/audit using one command
  4. From /var/log/audit, go up two levels using ..
  5. Create a chain: home โ†’ /etc โ†’ /var โ†’ /usr โ†’ home, documenting each step
Click to reveal solution
# Task 1: Jump to /var/log and back
cd /var/log
pwd
cd
pwd

# Task 2: Toggle between directories
cd /usr/share/doc
pwd
cd ~
pwd
cd -
pwd

# Task 3: Direct navigation
cd /var/log/audit

# Task 4: Go up two levels
cd ../..
pwd
# Should be in /var

# Task 5: Directory chain
cd ~          # Start at home
pwd
cd /etc       # Go to /etc
pwd
cd /var       # Go to /var
pwd
cd /usr       # Go to /usr
pwd
cd           # Return home
pwd

Lab 5: Combining ls Options (Intermediate)

Tasks:

  1. List all files in home directory, long format, human-readable, sorted by time
  2. Find the 5 largest files in /var/log
  3. List all files in /etc that end with .conf (don't use wildcards yet)
  4. Show the permissions of the /var/log directory itself (not its contents)
  5. List files in /usr/bin showing inode numbers
Click to reveal solution
# Task 1: Combined ls options
ls -laht ~

# Task 2: 5 largest files in /var/log
ls -lSh /var/log | head -6
# (head -6 because first line is "total")

# Task 3: List .conf files (using ls output with grep)
ls -l /etc | grep "\.conf$"

# Task 4: Show directory permissions
ls -ld /var/log

# Task 5: Show inode numbers
ls -li /usr/bin | head -20

Lab 6: Path Understanding (Advanced)

Tasks:

  1. From /usr/bin, navigate to /usr/share using relative path with ..
  2. From /var/log, navigate to /var/www using relative path
  3. Create navigation path: /var/log/audit โ†’ /etc/ssh using shortest relative path
  4. List files in your home directory while you're in /tmp
  5. Explain the difference between ls /etc and cd /etc && ls
Click to reveal solution
# Task 1: /usr/bin to /usr/share
cd /usr/bin
cd ../share
pwd

# Task 2: /var/log to /var/www
cd /var/log
cd ../www
pwd

# Task 3: /var/log/audit to /etc/ssh
cd /var/log/audit
cd ../../../etc/ssh
pwd

# Task 4: List home while in /tmp
cd /tmp
ls ~

# Task 5: Difference explanation
# ls /etc - Lists contents of /etc but stays in current directory
# cd /etc && ls - Changes to /etc THEN lists (now you're in /etc)

Lab 7: Hidden Files Deep Dive (Advanced)

Tasks:

  1. List all hidden directories in your home directory
  2. Find configuration files (.bashrc, .bash_profile) and note their sizes
  3. Check permissions on .ssh directory (if it exists)
  4. List all files in home that were modified today
  5. Find the oldest file in your home directory
Click to reveal solution
# Task 1: Hidden directories only
ls -lad ~/.*
# Or more precisely:
ls -la ~ | grep "^d" | grep "^\."

# Task 2: Config files
ls -lh ~/.bashrc ~/.bash_profile

# Task 3: .ssh permissions
ls -ld ~/.ssh
# Should be drwx------ (700) for security

# Task 4: Files modified today
ls -lrt ~ | tail -10

# Task 5: Oldest file
ls -lrt ~ | head -10

Lab 8: Working with Different Directories (Advanced)

Tasks:

  1. Compare contents of /bin and /usr/bin (just count files)
  2. Find total disk space used by files in your home directory
  3. List all socket files in /run
  4. Check if /root exists and try to list it as regular user
  5. Navigate through: / โ†’ /var โ†’ /var/log โ†’ back to / using cd commands
Click to reveal solution
# Task 1: Count files
ls /bin | wc -l
ls /usr/bin | wc -l

# Task 2: Total disk space (using du)
du -sh ~

# Task 3: Socket files in /run
ls -l /run | grep "^s"

# Task 4: Try to list /root
ls /root
# Should get: Permission denied

# Task 5: Navigation path
cd /
pwd
cd var
pwd
cd log
pwd
cd /
pwd

Lab 9: ls -l Interpretation Challenge (Advanced)

Given this ls -l output, answer the questions:

drwxr-xr-x.  2 apache apache   4096 Oct 15 14:23 web-app
-rw-r--r--.  1 root   root      847 Oct 20 09:15 config.txt
-rwxr-x--x.  1 centos9 wheel    512 Nov  1 11:00 deploy.sh
lrwxrwxrwx.  1 root   root       11 Sep  5 08:00 link -> config.txt

Questions:

  1. Which entries are directories?
  2. Which files can be executed by the owner?
  3. Which file is owned by the apache user?
  4. Can members of the wheel group read deploy.sh?
  5. What type of file is link?
  6. Which file is largest?
  7. Which was modified most recently?
Click to reveal solution

Answers:

  1. Directories: web-app (starts with d)
  2. Executable by owner: deploy.sh (owner has x permission)
  3. Owned by apache: web-app (owner column shows apache)
  4. Group read on deploy.sh: Yes (group has r-x)
  5. Type of link: Symbolic link (starts with l)
  6. Largest file: web-app at 4096 bytes
  7. Most recent: deploy.sh (Nov 1 11:00)

Lab 10: Real-World Navigation Scenarios (Expert)

Scenario 1: You're troubleshooting a web server issue.

  1. Check you're logged in as correct user
  2. Navigate to /var/log/httpd (or /var/log/apache2)
  3. List files sorted by most recent modification
  4. Go to web root /var/www/html
  5. Return to log directory quickly

Scenario 2: You need to audit user home directories.

  1. List all directories in /home
  2. Check which users have .ssh directories
  3. For each user, check if .bash_history exists
  4. Find largest home directory

Scenario 3: System configuration audit.

  1. List all .conf files in /etc
  2. Find recently modified configuration files (last 24 hours)
  3. Check ownership and permissions on /etc/passwd and /etc/shadow
  4. Navigate to /etc/ssh and examine config files
Click to reveal solution framework
# Scenario 1: Web server troubleshooting
whoami
cd /var/log/httpd  # or /var/log/apache2
ls -lt
cd /var/www/html
pwd
cd -

# Scenario 2: User audit
ls -l /home
for user in /home/*; do ls -ld $user/.ssh 2>/dev/null; done
ls -la /home/*/.bash_history
du -sh /home/* | sort -h

# Scenario 3: Configuration audit
ls -l /etc/*.conf
find /etc -name "*.conf" -mtime -1
ls -l /etc/passwd /etc/shadow
cd /etc/ssh
ls -l

๐Ÿ“š Best Practices

  1. Always verify after navigation

    cd /var/log
    pwd  # Confirm you're in the right place
    
  2. Use absolute paths for critical operations

    # Good - explicit and clear
    cd /etc/systemd/system
    
    # Can be confusing if you're not sure where you are
    cd ../../etc/systemd/system
    
  3. Use cd - to toggle between work locations

    cd /var/log      # Work in logs
    cd ~/scripts     # Check your scripts
    cd -             # Back to logs
    cd -             # Back to scripts
    
  4. Combine pwd with other commands

    echo "Currently in: $(pwd)"
    

ls Best Practices

  1. Use human-readable sizes

    ls -lh  # Much easier to read than bytes
    
  2. Sort by time when troubleshooting

    ls -lt /var/log  # See most recent log activity
    
  3. Always use -a when looking for config

    ls -la ~/.ssh/  # Don't miss hidden files
    
  4. Use -d for directory properties

    ls -ld /var/log  # Show dir itself, not contents
    
  5. Combine options efficiently

    ls -laht  # All files, long format, human-readable, time-sorted
    

Safety Practices

  1. Verify user with whoami before sudo/dangerous commands

    whoami  # Check you're not root!
    sudo rm -rf /old-backups/*
    
  2. Use pwd before creating/deleting files

    pwd  # Make sure you're in the right place
    touch newfile.txt
    
  3. Use ls to verify before acting

    ls -l *.log  # See what you're about to delete
    rm *.log     # Now delete with confidence
    

๐Ÿšจ Common Pitfalls to Avoid

Pitfall 1: Confusing cd - with cd ..

# WRONG understanding:
cd -   # This does NOT go to parent directory
cd ..  # This goes to parent directory

# CORRECT understanding:
cd -   # Goes to previous directory (wherever you were before)
cd ..  # Goes to parent directory (one level up)

Pitfall 2: Not Using Quotes with Spaces

# WRONG:
cd My Documents  # Error: too many arguments

# CORRECT:
cd "My Documents"
# Or
cd My\ Documents
โš ๏ธ

โš ๏ธ Best Practice: Avoid spaces in Linux filenames and directories. Use underscores or hyphens instead: my_documents or my-documents

Pitfall 3: Forgetting About Hidden Files

# WRONG - misses configuration files:
ls /home/centos9  # Only shows visible files

# CORRECT - shows everything:
ls -a /home/centos9  # Shows hidden config files

Pitfall 4: Misreading ls -l Permissions

-rwxr-xr-x  1 user group  1024 Oct 31 15:00 script.sh

# DON'T confuse:
# - First character (file type) with permissions
# - Owner/group/other permission groups
# - File size with number of links

Pitfall 5: Not Verifying Location

# DANGEROUS:
cd /var/log
# ... do some other commands ...
# ... forget where you are ...
rm *.txt  # Might delete the wrong files!

# SAFE:
pwd  # Always verify before destructive operations
ls   # See what's here
# Now proceed with confidence

Pitfall 6: Using cd Without Checking Results

# BAD:
cd /var/log/nonexistent
ls  # You're still in the previous directory!

# GOOD:
cd /var/log/nonexistent || echo "Directory doesn't exist"
# Or
cd /var/log/nonexistent && pwd

๐Ÿ“ Command Cheat Sheet

whoami Command

whoami              # Show current username
whoami --help       # Show help
whoami --version    # Show version

pwd Command

pwd                 # Show current directory (absolute path)
pwd -L              # Logical pwd (default, shows symlink path)
pwd -P              # Physical pwd (resolves symlinks)

cd Command

cd                  # Go to home directory
cd ~                # Go to home directory (explicit)
cd /path/to/dir     # Go to specific directory (absolute)
cd relative/path    # Go to relative directory
cd ..               # Go to parent directory
cd ../..            # Go up two levels
cd -                # Go to previous directory (toggle)
cd ~username        # Go to username's home directory

ls Command

# Basic listing
ls                  # List current directory
ls /path            # List specific directory
ls file.txt         # List specific file

# Show hidden files
ls -a               # All files (including hidden)
ls -A               # Almost all (excludes . and ..)

# Long format
ls -l               # Long format (detailed)
ls -lh              # Long format, human-readable sizes
ls -la              # Long format, all files
ls -lah             # Long format, all files, human-readable

# Sorting options
ls -lt              # Sort by modification time (newest first)
ls -ltr             # Sort by time (oldest first)
ls -lS              # Sort by size (largest first)
ls -lSr             # Sort by size (smallest first)

# Other useful options
ls -R               # Recursive (include subdirectories)
ls -d */            # List directories only
ls -ld /var         # List directory itself, not contents
ls -li              # Show inode numbers
ls -1               # One file per line

# Combining options
ls -laht            # All files, long, human-readable, sorted by time
ls -lhSr            # Long, human-readable, sorted by size (ascending)
ls -latr            # All files, long, sorted by time (oldest first)

๐ŸŽฏ Key Takeaways

  1. whoami tells you which user you currently are - critical before running privileged commands

  2. pwd shows your current directory location - always verify before creating/deleting files

  3. cd navigation shortcuts:

    • cd or cd ~ โ†’ home directory
    • cd .. โ†’ parent directory
    • cd - โ†’ previous directory (toggle)
    • These shortcuts save enormous amounts of time!
  4. ls shows directory contents:

    • ls -a โ†’ shows hidden files (essential for config files)
    • ls -l โ†’ detailed information (permissions, ownership, size, timestamp)
    • ls -al โ†’ complete view (combine options)
  5. ls -l output contains nine fields:

    • File type and permissions
    • Hard links
    • Owner and group
    • Size
    • Timestamp
    • Filename
  6. Hidden files (dotfiles) start with . and contain important configurations

  7. Always verify - check your location and user before critical operations

๐Ÿš€ What's Next?

You've mastered navigation! You can now move confidently through the Linux filesystem. In the next post, we'll learn about the touch command, which creates files and modifies timestamps - a crucial skill for system administration and understanding how Linux tracks file changes.

Coming up in Part 8: Understanding File Timestamps with touch

  • Creating empty files
  • Understanding access time vs modification time
  • How timestamps work in Linux
  • Why timestamps matter for backups and troubleshooting
  • And much more!

โœ…

๐ŸŽ‰ Congratulations! You've completed Part 7 of the LFCS Certification series. You now have solid navigation skills and understand how to use whoami, pwd, cd, and ls effectively. These commands will be second nature to you soon - practice them daily!

Keep Learning: Try navigating your Linux system right now. Practice the cd shortcuts and use ls -la to explore different directories. The more you practice, the more comfortable you'll become!

Owais

Written by Owais

I'm an AIOps Engineer with a passion for AI, Operating Systems, Cloud, and Securityโ€”sharing insights that matter in today's tech world.

I completed the UK's Eduqual Level 6 Diploma in AIOps from Al Nafi International College, a globally recognized program that's changing careers worldwide. This diploma is:

  • โœ… Available online in 17+ languages
  • โœ… Includes free student visa guidance for Master's programs in Computer Science fields across the UK, USA, Canada, and more
  • โœ… Comes with job placement support and a 90-day success plan once you land a role
  • โœ… Offers a 1-year internship experience letter while you studyโ€”all with no hidden costs

It's not just a diplomaโ€”it's a career accelerator.

๐Ÿ‘‰ Start your journey today with a 7-day free trial

Related Articles

Continue exploring with these handpicked articles that complement what you just read

More Reading

One more article you might find interesting