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 aspwd- Finding your current directory locationcd- Changing directories with powerful shortcutscd ~- Quick jump to home directorycd -- Toggle between two directoriescd ..- Move up to parent directoryls- List directory contentsls -a- Show hidden files (dotfiles)ls -l- Long format with detailed informationls -al- Combining options for complete view- Understanding every field in
ls -loutput - 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
centos9user
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:
- Started in
/home/centos9(home directory) - Changed to
/var/logdirectory - 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 directorycd ~โ 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 directorycd ..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/etcwent from/varto/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:
- Changed to
/var/log - Went back to home (
~) - Used
cd -to go back to/var/log - 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
| Command | What It Does | Example |
|---|---|---|
cd | Go to home directory | cd |
cd ~ | Go to home directory (explicit) | cd ~ |
cd /path | Go to specific absolute path | cd /var/log |
cd .. | Go to parent directory (up one level) | cd .. |
cd ../.. | Go up two levels | cd ../.. |
cd - | Go to previous directory (toggle) | cd - |
cd ./subdir | Go 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:
-aflag 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:
| Field | Value | Meaning |
|---|---|---|
| 1. File Type | - | Regular file (- = file, d = directory, l = link) |
| 2. Permissions | rw-r--r-- | Owner: read+write, Group: read, Others: read |
| 3. SELinux Context | . | Has SELinux context (RedHat/CentOS feature) |
| 4. Hard Links | 1 | Number of hard links (usually 1 for files) |
| 5. Owner | centos9 | User who owns the file |
| 6. Group | centos9 | Group that owns the file |
| 7. Size | 1077 | File size in bytes |
| 8. Timestamp | Oct 1 13:11 | Last modification date and time |
| 9. Filename | file_list.txt | Name of the file |
File Type Indicators
The first character tells you what type of entry it is:
| Character | Type | Example |
|---|---|---|
| - | Regular file | -rw-r--r-- file.txt |
| d | Directory | drwxr-xr-x Desktop |
| l | Symbolic link | lrwxrwxrwx link โ target |
| b | Block device | brw-rw---- sda |
| c | Character device | crw-rw-rw- tty |
| s | Socket | srwxr-xr-x socket |
| p | Named 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:
- File type:
-(file) vsd(directory) - Permissions: Files rarely need execute (
x), directories always need it to enter - 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_historyhas permissionsrw-------(owner only - good for security!) - Configuration files like
.bashrcand.bash_profile
Other Useful ls Options
| Option | What It Does | Example |
|---|---|---|
-h | Human-readable sizes (KB, MB, GB) | ls -lh |
-t | Sort by modification time (newest first) | ls -lt |
-r | Reverse sort order | ls -ltr |
-S | Sort by file size (largest first) | ls -lS |
-R | Recursive (list subdirectories too) | ls -R |
-d | List directory itself, not contents | ls -ld /var |
-i | Show inode numbers | ls -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:
- Check which user you're logged in as
- Find out what directory you're currently in
- List all files in your current directory
- Navigate to
/etcand verify you're there - Return to your home directory
- List files in
/var/logwithout 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:
- List all files including hidden ones in your home directory
- Find and view the
.bashrcfile (just check if it exists) - Count how many hidden files are in your home directory
- List all hidden files that start with
.bash - Check if you have a
.sshdirectory
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:
- List
/etc/passwdin long format - Identify: file type, permissions, owner, group, size, timestamp
- Find the largest file in your home directory
- Find the most recently modified file in
/etc - List
/tmpshowing 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:
- Go to
/var/log/and then jump back to home usingcdshortcut - From home, go to
/usr/share/doc, then back home, then toggle back usingcd - - Navigate from home to
/var/log/auditusing one command - From
/var/log/audit, go up two levels using.. - 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:
- List all files in home directory, long format, human-readable, sorted by time
- Find the 5 largest files in
/var/log - List all files in
/etcthat end with.conf(don't use wildcards yet) - Show the permissions of the
/var/logdirectory itself (not its contents) - List files in
/usr/binshowing 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:
- From
/usr/bin, navigate to/usr/shareusing relative path with.. - From
/var/log, navigate to/var/wwwusing relative path - Create navigation path:
/var/log/auditโ/etc/sshusing shortest relative path - List files in your home directory while you're in
/tmp - Explain the difference between
ls /etcandcd /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:
- List all hidden directories in your home directory
- Find configuration files (
.bashrc,.bash_profile) and note their sizes - Check permissions on
.sshdirectory (if it exists) - List all files in home that were modified today
- 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:
- Compare contents of
/binand/usr/bin(just count files) - Find total disk space used by files in your home directory
- List all socket files in
/run - Check if
/rootexists and try to list it as regular user - Navigate through:
/โ/varโ/var/logโ back to/usingcdcommands
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:
- Which entries are directories?
- Which files can be executed by the owner?
- Which file is owned by the
apacheuser? - Can members of the
wheelgroup readdeploy.sh? - What type of file is
link? - Which file is largest?
- Which was modified most recently?
Click to reveal solution
Answers:
- Directories:
web-app(starts withd) - Executable by owner:
deploy.sh(owner hasxpermission) - Owned by apache:
web-app(owner column showsapache) - Group read on deploy.sh: Yes (group has
r-x) - Type of link: Symbolic link (starts with
l) - Largest file:
web-appat 4096 bytes - Most recent:
deploy.sh(Nov 1 11:00)
Lab 10: Real-World Navigation Scenarios (Expert)
Scenario 1: You're troubleshooting a web server issue.
- Check you're logged in as correct user
- Navigate to
/var/log/httpd(or/var/log/apache2) - List files sorted by most recent modification
- Go to web root
/var/www/html - Return to log directory quickly
Scenario 2: You need to audit user home directories.
- List all directories in
/home - Check which users have
.sshdirectories - For each user, check if
.bash_historyexists - Find largest home directory
Scenario 3: System configuration audit.
- List all
.conffiles in/etc - Find recently modified configuration files (last 24 hours)
- Check ownership and permissions on
/etc/passwdand/etc/shadow - Navigate to
/etc/sshand 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
Navigation Best Practices
-
Always verify after navigation
cd /var/log pwd # Confirm you're in the right place -
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 -
Use
cd -to toggle between work locationscd /var/log # Work in logs cd ~/scripts # Check your scripts cd - # Back to logs cd - # Back to scripts -
Combine pwd with other commands
echo "Currently in: $(pwd)"
ls Best Practices
-
Use human-readable sizes
ls -lh # Much easier to read than bytes -
Sort by time when troubleshooting
ls -lt /var/log # See most recent log activity -
Always use -a when looking for config
ls -la ~/.ssh/ # Don't miss hidden files -
Use -d for directory properties
ls -ld /var/log # Show dir itself, not contents -
Combine options efficiently
ls -laht # All files, long format, human-readable, time-sorted
Safety Practices
-
Verify user with whoami before sudo/dangerous commands
whoami # Check you're not root! sudo rm -rf /old-backups/* -
Use pwd before creating/deleting files
pwd # Make sure you're in the right place touch newfile.txt -
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
-
whoami tells you which user you currently are - critical before running privileged commands
-
pwd shows your current directory location - always verify before creating/deleting files
-
cd navigation shortcuts:
cdorcd ~โ home directorycd ..โ parent directorycd -โ previous directory (toggle)- These shortcuts save enormous amounts of time!
-
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)
-
ls -l output contains nine fields:
- File type and permissions
- Hard links
- Owner and group
- Size
- Timestamp
- Filename
-
Hidden files (dotfiles) start with
.and contain important configurations -
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!

