Bash and Command Line Guide: Essential Terminal Skills for Developers

Learn the essential Bash commands and terminal skills every developer needs. Navigate files, write scripts, manage processes, and automate tasks.

Key Takeaways

  • Navigation, file operations, and process management are the three core command line skill areas
  • Pipes and redirection let you chain commands to process data without temporary files
  • Bash scripts automate repetitive tasks — if you do something twice, script it
  • Understanding exit codes and stderr vs stdout is essential for reliable scripting
  • SSH, SCP, and rsync are the essential remote tools every developer uses regularly

The command line intimidates beginners, but once it clicks, you'll wonder how anyone works without it. Every developer, data scientist, and DevOps engineer lives in the terminal. AI engineers need it for running scripts, managing servers, and working with cloud tools. This guide covers the commands you'll actually use — not an exhaustive reference, just the essential 20% that handles 80% of real work.

Commands you'll type hundreds of times: pwd (print working directory — where am I?), ls (list directory contents — what's here?), ls -la (long format with hidden files), cd directory (change directory), cd .. (go up one level), cd ~ (go to home directory). File operations: mkdir folder (make directory), touch file.txt (create empty file), cp source dest (copy), mv source dest (move or rename), rm file (remove file — be careful, no trash), rm -rf folder (remove folder recursively — very careful). cat file.txt (show file contents), less file.txt (paginated view — q to quit).

Pipes and Redirection: Chain Commands Together

The pipe operator | sends the output of one command as input to another. ls -la | grep '.txt' lists files then filters for .txt. cat data.csv | sort | uniq shows unique sorted values. ps aux | grep python finds running Python processes. Redirection: > writes output to a file (overwrites), >> appends to a file, 2> redirects errors, &> redirects both stdout and stderr. Examples: ls > files.txt (save file list to text file), python script.py > output.log 2>&1 (save all output including errors to log file).

Search and Filter: Find What You Need Fast

grep 'pattern' file searches for text in files. grep -r 'pattern' . searches recursively in current directory. grep -i case insensitive, grep -n shows line numbers, grep -v inverts (shows non-matching lines). find . -name '*.py' finds files by name pattern. find . -type f -mtime -7 finds files modified in last 7 days. wc -l file counts lines. sort file sorts alphabetically. uniq removes consecutive duplicates (usually pipe from sort first). head -n 20 file and tail -n 20 file show first/last 20 lines. tail -f logfile follows a log file in real time — essential for monitoring.

Bash Scripting: Automate Repetitive Tasks

Start any bash script with #!/bin/bash (the shebang line). Make it executable: chmod +x script.sh. Run it: ./script.sh. Key scripting constructs:

#!/bin/bash
# Variables
NAME='World'
echo "Hello, $NAME!"

# If statement
if [ -f 'data.csv' ]; then
  echo 'File exists'
else
  echo 'File not found'
fi

# For loop
for file in *.py; do
  echo "Processing $file"
  python "$file"
done

# Check exit code
python train.py
if [ $? -eq 0 ]; then
  echo 'Training succeeded'
fi

Process Management: Control Running Programs

ps aux lists all running processes. top or htop shows real-time resource usage. kill PID sends a signal to a process — kill -9 PID forces it. pkill process_name kills by name. Background processes: append & to run a command in the background (python server.py &). jobs lists background jobs. fg brings a job to foreground. ctrl+c kills the foreground process. ctrl+z suspends it (then bg to continue in background). nohup command & runs a command that survives terminal close — critical for long-running server processes.

SSH and Remote Tools: Work on Servers

ssh user@server connects to a remote server. Add your public key to ~/.ssh/authorized_keys on the server for passwordless login. Configure shortcuts in ~/.ssh/config: add a Host block with hostname, user, and identity file, then just type ssh myserver. File transfer: scp file.txt user@server:/path/ copies files to remote. rsync -avz local/ user@server:/remote/ syncs directories efficiently (only transfers changes). scp -r folder/ user@server:/path/ copies directories. For cloud: AWS CLI, GCP SDK, and Azure CLI all have commands that run in bash — once you know the terminal, the cloud becomes much more manageable.

Frequently Asked Questions

How long does it take to learn the command line?
Basic navigation and file operations can be learned in a few hours. Getting comfortable with pipes, search, and common tools takes a week of daily use. Bash scripting proficiency takes a month or more of practice.
Should I learn Bash or Zsh?
Zsh (the default on macOS) is Bash-compatible with extra features like better autocomplete and plugins via Oh My Zsh. Learn Bash syntax — it works in both shells and in most servers which run Bash by default.
Is the command line necessary for AI and data science?
Yes. Running Python scripts, managing virtual environments, working with Git, deploying models, and using cloud services all happen in the terminal. You can't avoid it and wouldn't want to once you're comfortable.
What are the most dangerous Bash commands?
rm -rf with wildcards or wrong paths can delete critical files permanently. Piping unknown output to shell (curl | bash) can execute malicious code. Always double-check destructive commands before running them, especially on servers.

Ready to Level Up Your Skills?

Terminal skills, Python scripting, cloud tools, and AI development all come together at our hands-on bootcamp. We build real things in 3 days. Next cohorts October 2026 in Denver, NYC, Dallas, LA, and Chicago. Only $1,490.

View Bootcamp Details

About the Author

Bo Peng is an AI Instructor and Founder of Precision AI Academy. He has trained 400+ professionals in AI, machine learning, and cloud technologies. His bootcamps run in Denver, NYC, Dallas, LA, and Chicago.