Skip to main content

Linux CLI Essentials (Bash Commands & Command Line Basics)

What is a command line?

A command line is a text interface where you type commands in the command line to control the computer. On Linux, you usually use a shell (like bash or zsh) inside a terminal.

If you’ve wondered “what is a command line?”: it’s simply a faster, scriptable way to work with files, programs, and servers.

What is a shell in Linux?

A shell in Linux is the program that reads your input and runs it. A shell command is anything you type that the shell can execute: a built-in (cd) or a program (ls, grep).

Common shells:

  • bash (most common)
  • zsh
  • fish

Linux basics you need once

Paths: what is “.” and “..” in Linux?

  • . = current directory
  • .. = parent directory

Absolute vs relative:

  • absolute: /home/daria/projects/my-app
  • relative: ./src or ../logs

Streams: stdin, stdout, stderr

  • stdin: input
  • stdout: normal output
  • stderr: errors

Redirection:

  • > overwrite
  • >> append
  • 2> redirect errors
  • | pipe output into another command

Bash commands (command line command list)

These are the basic cmd commands you’ll use daily:

pwd
ls
ls -la
cd /path/to/dir
cd ..

View files and logs

cat file.txt
less file.txt
tail -n 200 logs/app.log
tail -f logs/app.log

Search text (TODOs, errors)

grep -R --line-number "TODO" .
grep -R --line-number --exclude-dir=node_modules "ERROR" .

Copy/move/remove safely

cp a.txt b.txt
mv old.txt new.txt
mkdir -p backups
rm -i file.txt

Permissions and ownership

ls -l
chmod u+x script.sh
chown user:group file.txt

Step-by-step workflow (real daily use)

Goal: open a project, find TODOs, inspect logs, edit config, make a backup.

cd ~/projects/my-app
pwd
ls -la

grep -R --line-number --exclude-dir=node_modules "TODO" --include="*.js" --include="*.py" .

tail -n 100 logs/app.log
tail -f logs/app.log

cp config.yml "config.yml.$(date +%F_%H%M%S).bak"

nano config.yml
# or
vim config.yml

Linux show services (what’s running)

If you’re on a systemd-based distro (most servers and desktops), use systemctl:

# list running services
systemctl list-units --type=service --state=running

# check one service
systemctl status nginx

# logs for a service
journalctl -u nginx -n 200
journalctl -u nginx -f

If you need a quick process view:

ps aux | grep nginx
top

“What does this mean in Linux?” (common patterns)

Permission denied

You lack permission. Check:

ls -l file

Fix by changing permissions/owner, or use sudo only if necessary.

Command not found

The program isn’t installed or not in PATH.

which somecommand
echo "$PATH"

What is “type” in Linux?

type tells you what a command is (binary vs alias vs built-in):

type cd
type ls
type grep

Best practices (avoid common mistakes)

  • Prefer less over cat for big files.

  • Use Ctrl+R to search history.

  • Use --help and man: man grep, systemctl --help.

  • Before editing important files, make a timestamped backup.

  • Don’t run everything as root. Use sudo only when needed.

  • When deleting, consider moving to a temp folder first:

    mkdir -p ~/trash && mv file.txt ~/trash/

What to use Linux for

Using Linux (and the CLI) is best for:

  • remote servers (SSH)
  • log inspection and debugging
  • automation via scripts
  • repeatable workflows in dev/ops

Not ideal for:

  • visual design tasks
  • workflows where a GUI is safer for non-technical users

Key takeaways

  • Learn a small set of bash commands and you can do 90% of daily work.
  • Pipes and redirection let you combine tools quickly.
  • For servers, knowing how to show services in Linux and read logs saves hours.
  • Safety comes from habits: quoting paths, backups, and cautious sudo.