G
GuideDevOps
Lesson 3 of 17

Basic Commands

Part of the Linux Fundamentals tutorial series.

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/admin

Sample 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.yaml

Long Listing with Details

The -la flags show hidden files and detailed metadata:

FlagMeaning
-lLong format with permissions, owner, size, date
-aShow 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.yaml

Column meanings in long listing:

ColumnExampleMeaning
Permissionsdrwxr-xr-xType + read/write/execute for owner/group/other
Hard links5Number of hard links to this file
OwneradminWho owns the file
GroupadminGroup assigned to the file
Size4096File size in bytes
DateApr 10 09:15Last modification time
NameprojectsFile 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/log

Moving 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/log

Quick shortcuts:

ShortcutMeaning
cdGo home
cd ~Go home
cd -Go to previous directory
cd ..Go up one level
cd ../..Go up two levels

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.txt

DevOps 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 20260410

The -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.bak

Useful flags:

FlagMeaning
-rCopy directories recursively
-pPreserve file attributes (permissions, timestamps)
-vVerbose — show what is being copied
# Copy directory with preserved permissions
cp -rp /etc/nginx /tmp/nginx-backup

Move 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-archive

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-deploy

Quick Reference Card

TaskCommand
Show current directorypwd
List filesls
List with detailsls -la
List hidden filesls -a
Change directorycd /path
Go homecd ~
Go up one levelcd ..
Go to previous dircd -
Create empty filetouch file.txt
Create directorymkdir dir
Create nested dirsmkdir -p path/to/deep/dir
Copy filecp src dst
Copy directorycp -r src dst
Move/Renamemv src dst
Remove filerm file.txt
Remove directoryrm -rf dir

Practice Challenge

Try these on a Linux system to build muscle memory:

  1. Navigate to /tmp and create a directory structure: projects/app/backend/logs
  2. Create a file README.md in the backend directory
  3. Copy the README to README.bak
  4. List all files including hidden ones
  5. Remove the backup file and the entire directory structure you just created