Navigating the CLI
As a DevOps engineer, you will spend most of your time in the Command Line Interface (CLI). Every server you deploy to, every container you manage, every log you tail — it all happens in the terminal. Mastering these core navigation commands is your first step.
Where Am I? — pwd
The pwd command (Print Working Directory) shows your current location in the filesystem.
$ pwd
/home/adminSample Output:
/home/admin
Why it matters in DevOps: When you SSH into a server, you often land in your home directory. Use pwd to confirm where you are before running commands that might affect the wrong location.
What is Here? — ls
The ls command lists files and directories.
Basic Listing
$ ls
Documents Downloads projects config.yamlLong Listing with Details
The -la flags show hidden files and detailed metadata:
| Flag | Meaning |
|---|---|
-l | Long format with permissions, owner, size, date |
-a | Show hidden files (starting with .) |
$ ls -la
total 48
drwxr-xr-x 5 admin admin 4096 Apr 10 09:15 .
drwxr-xr-x 3 root root 4096 Apr 10 08:00 ..
-rw-r--r-- 1 admin admin 220 Apr 9 15:30 .bashrc
-rw------- 1 admin admin 3154 Apr 10 09:15 .bash_history
drwxr-xr-x 3 admin admin 4096 Apr 9 14:22 .ssh
drwxr-xr-x 3 admin admin 4096 Apr 10 09:00 projects
-rw-r--r-- 1 admin admin 894 Apr 10 08:45 config.yamlColumn meanings in long listing:
| Column | Example | Meaning |
|---|---|---|
| Permissions | drwxr-xr-x | Type + read/write/execute for owner/group/other |
| Hard links | 5 | Number of hard links to this file |
| Owner | admin | Who owns the file |
| Group | admin | Group assigned to the file |
| Size | 4096 | File size in bytes |
| Date | Apr 10 09:15 | Last modification time |
| Name | projects | File or directory name |
Useful ls Variations for DevOps
# List files sorted by size (largest first) — useful for finding large files
ls -lhS
# List files by modification time (newest first) — useful for finding recent changes
ls -lht
# Append indicator for file types (/ for directories, * for executables)
ls -laF
# Recursive listing — see entire directory tree
ls -laR /var/logMoving Around — cd
The cd command (Change Directory) navigates between folders.
Essential Navigation
# Navigate to a specific path
$ cd /var/log
$ pwd
/var/log
# Go up one level
$ cd ..
$ pwd
/var
# Go to your home directory immediately
$ cd ~
$ pwd
/home/admin
# Go back to previous directory
$ cd -
/var/logQuick shortcuts:
| Shortcut | Meaning |
|---|---|
cd | Go home |
cd ~ | Go home |
cd - | Go to previous directory |
cd .. | Go up one level |
cd ../.. | Go up two levels |
. means "current directory" and .. means "parent directory". These are relative to your current position.File and Folder Operations
Create a File — touch
Creates an empty file or updates timestamp of existing file.
$ touch newfile.txt
$ ls -la newfile.txt
-rw-r--r-- 1 admin admin 0 Apr 10 10:30 newfile.txtDevOps use case: Touch is useful for creating placeholder config files or marker files for deployment scripts.
Create a Directory — mkdir
# Create a single directory
$ mkdir configs
# Create nested directories (-p is essential for production scripts)
$ mkdir -p /tmp/app/deploy/logs/$(date +%Y%m%d)
$ ls -la /tmp/app/deploy/logs/
total 8
drwxr-xr-x 3 root root 4096 Apr 10 10:30 .
drwxr-xr-x 3 root root 4096 Apr 9 14:00 ..
drwxr-xr-x 3 root root 4096 Apr 10 10:30 20260410The -p flag is critical — without it, mkdir fails if parent directories don't exist.
Copy a File — cp
# Backup a config file
$ cp config.yaml config.yaml.bak
$ ls -la config.yaml*
-rw-r--r-- 1 admin admin 894 Apr 10 08:45 config.yaml
-rw-r--r-- 1 admin admin 894 Apr 10 10:35 config.yaml.bakUseful flags:
| Flag | Meaning |
|---|---|
-r | Copy directories recursively |
-p | Preserve file attributes (permissions, timestamps) |
-v | Verbose — show what is being copied |
# Copy directory with preserved permissions
cp -rp /etc/nginx /tmp/nginx-backupMove or Rename — mv
# Rename a file
$ mv oldname.txt newname.txt
# Move a file to another directory
$ mv report.pdf /home/admin/Documents/
# Move with verification
$ mv -v site.conf /etc/nginx/site.conf
renamed 'site.conf' -> '/etc/nginx/site.conf'Remove — rm
# Remove a single file
$ rm oldfile.txt
# Remove with confirmation
$ rm -i config.yaml
rm: remove regular file 'config.yaml'? y
# Recursively remove a directory and all contents
$ rm -rf /tmp/deploy-archiverm -rf, the files are permanently deleted instantly. There is no undo. Always double-check your path before executing.Safe practice: Use rm -i for interactive deletion or test your path with ls first:
# Verify what you are about to delete
$ ls /tmp/old-deploy
total 48
drwxr-xr-x 3 admin admin 4096 Apr 10 09:00 .
drwxr-xr-x 3 root root 4096 Apr 10 08:00 ..
-rw-r--r-- 1 admin admin 1024 Apr 10 09:00 app.log
-rw-r--r-- 1 admin admin 2048 Apr 10 09:00 deploy.sh
# Now delete with confidence
$ rm -rf /tmp/old-deployQuick Reference Card
| Task | Command |
|---|---|
| Show current directory | pwd |
| List files | ls |
| List with details | ls -la |
| List hidden files | ls -a |
| Change directory | cd /path |
| Go home | cd ~ |
| Go up one level | cd .. |
| Go to previous dir | cd - |
| Create empty file | touch file.txt |
| Create directory | mkdir dir |
| Create nested dirs | mkdir -p path/to/deep/dir |
| Copy file | cp src dst |
| Copy directory | cp -r src dst |
| Move/Rename | mv src dst |
| Remove file | rm file.txt |
| Remove directory | rm -rf dir |
Practice Challenge
Try these on a Linux system to build muscle memory:
- Navigate to
/tmpand create a directory structure:projects/app/backend/logs - Create a file
README.mdin thebackenddirectory - Copy the README to
README.bak - List all files including hidden ones
- Remove the backup file and the entire directory structure you just created