Linux Command Line Essentials
Navigate the file system, manage files, permissions, processes, and packages, and read logs from a Linux terminal.
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.
| Path | Purpose | Typical contents |
|---|---|---|
| / | Filesystem root | Top-level directories, not a regular user home |
| /home/learner | User home directory | Personal files and project checkouts |
| /etc | System configuration | Service and machine configuration files |
| /var/log | Variable data and logs | Logs and other changing service data |
| /tmp | Temporary working space | Short-lived files; do not store durable state here |
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.
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.
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'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.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.
# Inspect ownership and permissions before changing anything.
ls -l deploy.sh
chmod u+x deploy.sh
chmod 640 app.conf
stat app.confchmod -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.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.
# 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.logStandard 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.
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.
ps -ef | grep '[u]vicorn'
pgrep -a -f 'uvicorn app.main:app'
topA 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.
systemctl status my-api.service
journalctl -u my-api.service --since '15 minutes ago'- Identify the service or process and confirm the PID or unit name.
- Read recent logs and resource use before taking action.
- Use the service manager when it owns the process; avoid killing a guessed PID.
- Verify the service is healthy after a restart and note the change for the team.
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.
ssh learner@server.example.com
ssh -i ~/.ssh/team-dev-key learner@server.example.comPackage 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.
# Debian or Ubuntu: refresh package metadata, then install a known package.
sudo apt update
sudo apt install curl
# Query installed package information.
dpkg -l curlsudo 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.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.
Investigate a Small Service Incident
Practice
Use terminal evidence before changing the service
- Create a project directory and a sample log with success, warning, and failure lines; inspect it with less and tail.
- Use grep to count failures and find the request ID for one failed request.
- Use find to list configuration files under a test directory without searching the whole machine.
- Create a script file, inspect its permissions, add execute permission for its owner, and explain the change.
- 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.
Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.
