Mental model
Cisco objective 4.11 says “Utilize Bash commands (file management, directory navigation, and environmental variables)”. The core 15 commands cover 90% of every day shell work.
Why network engineers need bash:
- Config pushes often ride ssh + a shell script.
- Automation runners (CI/CD, Ansible, cron) run bash to glue steps together.
- Any Linux-based network device management (Catalyst Center server, Ubuntu jump host, container shell) uses bash.
Directory navigation
| Command | Does |
|---|---|
pwd | Print working directory |
ls | List files in current directory |
ls -la | Long listing including hidden files |
cd <dir> | Change into <dir> |
cd .. | Go up one directory |
cd ~ or cd | Go to your home directory |
mkdir <dir> | Create a directory |
mkdir -p a/b/c | Create nested directories |
File management
| Command | Does |
|---|---|
touch <file> | Create an empty file (or update timestamp if exists) |
cat <file> | Print the whole file |
head -n 5 <file> | First 5 lines |
tail -n 5 <file> | Last 5 lines |
cp src dst | Copy file |
cp -r src dst | Copy directory recursively |
mv src dst | Rename or move |
rm <file> | Delete file |
rm -rf <dir> | Delete directory recursively (DANGEROUS; no undo) |
Writing to files
| Pattern | Does |
|---|---|
echo "hello" > file.txt | Create file.txt with “hello” (overwrites) |
echo "another" >> file.txt | Append “another” to file.txt |
cat file1 file2 > combined.txt | Concatenate two files |
Searching
| Command | Does |
|---|---|
grep <pattern> <file> | Lines containing pattern |
grep -i <pattern> <file> | Case-insensitive |
grep -r <pattern> <dir> | Recursive through a directory |
wc -l <file> | Count lines |
Environment variables
Variables that live for the shell session (and inherited by child processes).
export MERAKI_KEY="abcdef0123456789"
echo $MERAKI_KEY
export VAR=valuesets a variable and marks it exported so child processes (python, docker, ssh) see it.echo $VARprints it.envlists every env var currently set.unset VARremoves it.
Common env vars:
PATH— colon-separated list of directories bash searches when you type a command.HOME— your home directory.USER— your username.PWD— current directory.
Persisting env vars
Add export lines to ~/.bashrc (or ~/.zshrc) to set them every time you open a shell.
.env files
A convention: put secrets in .env, add .env to .gitignore:
MERAKI_KEY=abcdef...
WEBEX_TOKEN=eyJhbG...
Load before running a script:
set -a; source .env; set +a
python my_script.py
pwd, ls, cd, mkdir, echo, cat, cp, mv, export
12 steps against a real engine. Walk the directory tree, create files, grep, set an env var, read it back.
Open the lab →The #1 mistake
rm -rf with a typo. rm -rf / deletes everything on the system (modern systems try to guard against the literal / but variations slip through). rm -rf $UNSET_VAR/something where $UNSET_VAR expands to empty becomes rm -rf /something. Habits:
- Prefer specific paths over glob patterns when deleting.
set -uat the top of a script fails loudly on an unset variable.trash-clias a safer alias on dev machines.
FAQ
bash vs zsh vs fish? bash is the baseline every Linux server has. zsh and fish are nicer interactive shells but your scripts should still target bash (shebang #!/bin/bash).
Why does my env var not survive a reboot? export only lasts for the current shell. Add it to ~/.bashrc (or system-wide /etc/environment) to persist.
What is set -euo pipefail? A common safety preamble in bash scripts: -e exits on first failing command, -u fails on unset vars, -o pipefail fails if any command in a pipe fails. Highly recommended.
I pressed Ctrl+S and the terminal froze. Ctrl+S is “stop output”; press Ctrl+Q to resume. Harmless but surprising if you have never hit it.
