Linux Command Line Essentials

Navigate the file system, manage files, permissions, processes, and packages, and read logs from a Linux terminal.

Est. 40 min Updated Suggest a fix
// Part 01 — Why the terminal matters

A Linux Server Is a Set of Files and Processes

Linux runs on cloud virtual machines, containers, CI workers, and many production services. A graphical desktop is useful for a personal computer, but a server is often managed remotely through a text terminal. The shell reads a command, asks the operating system to perform it, and prints the result. Learning a few dependable commands lets you inspect a service, find a configuration file, and diagnose a problem without guessing.

Commands are small programs. Their arguments usually identify the target or change the operation, and options often begin with a dash. The current directory is part of the context: a relative path is interpreted from there, while an absolute path starts at the root directory /. Use pwd to check that context before commands that modify files.

PathPurposeTypical contents
/Filesystem rootTop-level directories, not a regular user home
/home/learnerUser home directoryPersonal files and project checkouts
/etcSystem configurationService and machine configuration files
/var/logVariable data and logsLogs and other changing service data
/tmpTemporary working spaceShort-lived files; do not store durable state here
💡 Note
Use least privilege. Start as your ordinary user. A root shell can change any system file, so elevated access should be limited to a specific, understood administrative action.
// Part 02 — Navigation

Move Around Without Losing Your Place

pwd prints the working directory, ls lists entries, and cd changes the directory. The ~ character means your home directory; .. means the parent directory. Use ls -la to include hidden names (those beginning with a dot) and details such as permissions and ownership. Prefer explicit paths when a command should not depend on where you happen to be.

bash
pwd
ls -lah
cd ~/projects
pwd
ls -la
cd ..

Paths can contain spaces. Quote them so the shell passes one path argument instead of splitting it into several words. Tab completion can fill in a path and reduce typing errors. Before removing or moving anything, list the target and confirm it is the intended file; a typo in a destructive command is not automatically recoverable.

bash
mkdir -p ~/projects/incident-notes
cd ~/projects/incident-notes
printf '%s\n' 'service restarted after config check' > 'notes for review.txt'
cat 'notes for review.txt'
🎯 Pro Tip
Use man command or command --help to inspect options on the machine you are using. The installed version's documentation is more reliable than copying an unfamiliar flag from a random snippet.
// Part 03 — Files and permissions

Read, Create, and Protect Files

The common file tools have distinct purposes: cat prints a small file, less pages through a large one, head and tail show its beginning or end, cp copies, and mv moves or renames. mkdir -p creates a directory tree. Use rm carefully: it removes names rather than sending files to a recycle bin. Check a path with ls before removal.

Each file has an owner, a group, and permissions for owner, group, and everyone else. Read (r), write (w), and execute (x) mean different things for files and directories: execute on a directory allows traversing it. chmod changes permissions and chown changes ownership. Numeric modes combine the three permission bits for each class; do not choose a permissive mode merely to make an error disappear.

bash
# Inspect ownership and permissions before changing anything.
ls -l deploy.sh
chmod u+x deploy.sh
chmod 640 app.conf
stat app.conf
⚠️ Important
Avoid chmod -R 777 as a troubleshooting shortcut. It gives every local user broad access and can expose credentials or make executable files unexpectedly writable. Fix the specific owner or permission that is wrong.
// Part 04 — Search and streams

Find Evidence with grep, find, and Pipes

A pipe (|) sends one command's standard output into another command's standard input. This makes small tools composable: list files, filter lines, then count matches. grep searches text; findsearches directory trees by name, type, or other criteria. Quote patterns so the shell does not expand special characters before the search program receives them.

bash
# Search a log for failed requests, then count matching lines.
grep -i 'failed' /var/log/my-service/app.log | wc -l

# Find Python source files below the current project.
find . -type f -name '*.py' -print

# Read the latest lines while a service is writing to a log.
tail -n 40 /var/log/my-service/app.log

Standard input, standard output, and standard error are separate streams. Redirection with > replaces a file, while >> appends. Use a disposable file when testing redirection. A pipeline can hide an earlier failure unless you check the command's status or enable a pipeline-aware shell option in scripts; we will build on that idea in the next lesson.

📌 Real World Example
During a delivery API incident, filter the application log for a request ID, then inspect the surrounding lines. A concise query helps answer whether the request failed in the application, timed out upstream, or never reached it.
// Part 05 — Processes

Inspect Work, Then Stop It Deliberately

A process is a running program with a process ID (PID). ps gives a snapshot, top orhtop offers a live view when installed, and pgrep can find a PID by process name. A process launched in the foreground occupies the terminal; Ctrl+C asks it to stop. Signals sent withkill should target a process you have identified, not an arbitrary PID copied from old notes.

bash
ps -ef | grep '[u]vicorn'
pgrep -a -f 'uvicorn app.main:app'
top

A service managed by systemd is normally controlled with systemctl, and its journal can be inspected with journalctl. Service names differ by distribution and installation. Check the actual unit name and status before restarting it; restarting a production service can interrupt users.

bash
systemctl status my-api.service
journalctl -u my-api.service --since '15 minutes ago'
  1. Identify the service or process and confirm the PID or unit name.
  2. Read recent logs and resource use before taking action.
  3. Use the service manager when it owns the process; avoid killing a guessed PID.
  4. Verify the service is healthy after a restart and note the change for the team.
// Part 06 — Remote systems and packages

Connect Securely and Install from the Right Source

SSH opens an encrypted remote terminal session. Use the account and host supplied by your team, and verify host-key prompts against a trusted channel when connecting for the first time. Do not copy private keys into a project or paste them into chat. For regular access, an SSH agent can hold an unlocked key for the session instead of repeatedly exposing the key file.

bash
ssh learner@server.example.com
ssh -i ~/.ssh/team-dev-key learner@server.example.com

Package managers install and update software using repositories configured for the operating system. Debian and Ubuntu commonly use apt; Fedora uses dnf; other distributions have their own tools. The package manager resolves dependencies and tracks installed packages. Follow the distribution's supported process rather than downloading a privileged installer from an unverified site.

bash
# Debian or Ubuntu: refresh package metadata, then install a known package.
sudo apt update
sudo apt install curl

# Query installed package information.
dpkg -l curl
🎯 Pro Tip
Use sudo only for the command that needs administrator rights, and read the command before entering your password. A second terminal as root is harder to audit and easier to misuse.
// Part 07 — Pitfalls

Common Mistakes

Running a command from an unknown directory

Why: Relative paths are resolved from the current working directory.

Fix: Check pwd, list the target, and use an explicit path for risky operations.

Using sudo to bypass every permission error

Why: The original problem may be incorrect ownership or a wrong path.

Fix: Inspect ls -l and correct the narrow permission or ownership issue.

Assuming a grep pipeline succeeded

Why: By default, the pipeline status can reflect only its final command.

Fix: Check each the command output and status; use pipefail in scripts where appropriate.

Killing a process based on a stale PID

Why: PIDs can be reused after a process exits.

Fix: Look up the live process and prefer the owning service manager.

// Part 08 — Practice

Investigate a Small Service Incident

Practice

Use terminal evidence before changing the service

  1. Create a project directory and a sample log with success, warning, and failure lines; inspect it with less and tail.
  2. Use grep to count failures and find the request ID for one failed request.
  3. Use find to list configuration files under a test directory without searching the whole machine.
  4. Create a script file, inspect its permissions, add execute permission for its owner, and explain the change.
  5. On a machine with systemd, inspect a non-critical service status and recent journal entries; do not restart an unfamiliar service.

Hint: Use a directory you own for practice. Never test destructive commands against system paths or production services.

🎯 Key Takeaways

  • ✓A shell command acts in a current directory; use pwd and explicit paths to make context clear.
  • ✓Linux stores configuration, logs, user data, and temporary files in different parts of its filesystem.
  • ✓Permissions control reading, writing, execution, and directory traversal; change only the access that is needed.
  • ✓Pipes connect focused commands, while grep and find search file contents and paths respectively.
  • ✓Inspect process and service status before stopping or restarting anything.
  • ✓SSH provides remote access and package managers provide a traceable way to install software.

Next

What comes next

You can inspect a Linux system interactively. Next, combine commands into safe, repeatable scripts that report success or failure clearly.

Lesson 02 · Bash Scripting for Automation →

HELP US IMPROVE

How was this lesson?

Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.

Choose your feedback

Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.

Share

Discussion

0

Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.

Continue with GitHub
Loading...