1. Home
  2. Blog
  3. DevOps

DevOps

Linux Commands for Beginners: The Essential Terminal Guide With Examples

The terminal looks intimidating until you know a few dozen commands. Learn the ones that matter, grouped by what you are trying to do, then combine them to answer a real question about a log file.

9 min read
Linux commands for beginners: the essential terminal guide with examples

Key takeaways

  • A small set of Linux commands covers most daily work: ls, cd, cp, mv, rm, cat and grep.
  • Pipes (|) connect simple tools to answer harder questions.
  • rm has no recycle bin, so double-check before you press Enter.
  • Use man or --help whenever you forget an option.

Most servers, containers and cloud machines run Linux, and they usually do not have a graphical desktop. That is why learning Linux commands is such a useful skill for developers and testers alike. You do not need to memorize hundreds. A few dozen will carry you a long way.

We tested the file, search and pipe examples in Git Bash on Windows, which provides the same core tools, and the output comes from that run. We did not run the commands for permissions, services, packages and remote access, because they depend on a real Linux system. Details can vary by distribution, so check your own system’s documentation.

Getting started safely

You do not need to install Linux to practise. Good options include:

  • Windows: Windows Subsystem for Linux (WSL), or Git Bash for the basics.
  • macOS: the built-in Terminal, whose commands are very similar, though some options differ.
  • Any system: a container. Our Docker tutorial for beginners shows how to start one.

Practise in a throwaway folder, and remember that everything in Linux is case-sensitive: Notes.txt and notes.txt are different files.

Anatomy of a command

ls -l /var/log
^  ^  ^
|  |  argument: what to act on
|  option: how to behave
command: what to run

Short options can usually be combined, so ls -l -a and ls -la are the same. Long options use two dashes, as in --help. For help, run man ls for the full manual, or ls --help for a summary. Press q to leave a manual page.

Command What it does
pwd Prints your current folder
ls Lists files
ls -la Lists all files, including hidden ones, with details
cd folder Moves into a folder
cd .. Moves up one level
cd ~ Goes to your home folder
cd - Returns to the previous folder

Press Tab to auto-complete file names, and the up arrow to bring back earlier commands. These two habits save more time than any other tip here. A file name beginning with a dot, such as .env, is hidden, and ls shows it only with -a.

Manage files and folders

Command What it does
mkdir -p project/logs Creates folders, including parents
touch notes.txt Creates an empty file
cp a.txt b.txt Copies a file
cp -r src/ backup/ Copies a folder
mv a.txt b.txt Renames or moves a file
rm a.txt Deletes a file
rm -r folder/ Deletes a folder and everything in it

Here is a short session from our run:

$ mkdir -p project/logs
$ cd project
$ touch notes.txt
$ ls
logs  notes.txt

$ cp notes.txt backup.txt
$ mv backup.txt old.txt
$ ls
logs  notes.txt  old.txt

$ rm old.txt
$ ls
logs  notes.txt

Tip: rm does not use a recycle bin, and deleted files are generally gone. Be especially careful with rm -r and wildcards. Run ls with the same pattern first, to see exactly what would match, and use rm -i if you want a prompt for each file.

View file contents

Command What it does
cat file Prints a whole file
less file Scrolls through a long file (q to quit)
head -n 5 file Shows the first five lines
tail -n 5 file Shows the last five lines
tail -f file Follows new lines as they are written
wc -l file Counts lines

For the next few examples, we created a small log file:

$ cat logs/app.log
ERROR db down
INFO started
ERROR disk full
INFO stopped

$ head -n 1 logs/app.log
ERROR db down

$ tail -n 1 logs/app.log
INFO stopped

$ wc -l logs/app.log
4 logs/app.log

tail -f is a daily tool for watching a live application log while you reproduce a bug. Press Ctrl+C to stop it.

grep searches inside files, and find searches for the files themselves:

$ grep ERROR logs/app.log
ERROR db down
ERROR disk full

$ grep -c ERROR logs/app.log
2

$ find . -name "*.log"
./logs/app.log
Option Meaning
grep -i Ignores case
grep -r Searches a folder recursively
grep -n Shows line numbers
grep -v Shows lines that do not match
grep -c Counts matching lines

Pipes and redirection

This is the idea that makes the command line so powerful. Each tool does one small job, and you connect them:

Symbol What it does
| Sends one command’s output into the next
> Writes output to a file, replacing its contents
>> Appends output to a file
2> Writes error messages to a file
$ echo "hello" > greeting.txt
$ echo "world" >> greeting.txt
$ cat greeting.txt
hello
world

Be careful with a single >, because it silently overwrites what was already in the file.

A real example: summarize a log

How many lines of each type are in our log? Combining four simple commands gives the answer:

$ cut -d' ' -f1 logs/app.log | sort | uniq -c
      2 ERROR
      2 INFO

Reading from left to right: cut takes the first space-separated word on each line, sort groups identical words together, and uniq -c counts each group. The sort step matters, because uniq only collapses neighbouring duplicates. Add | sort -nr to the end to list the most common first.

This kind of one-liner is a great help when you are investigating failures. It can quickly tell you whether an error happened twice or two thousand times, which is useful detail to put in a bug report.

File permissions

Run ls -l and you will see something like this:

-rwxr-xr-- 1 asha devs 512 Nov 1 10:00 deploy.sh

After the first character, which shows the file type, there are three groups of three characters, for the owner, the group and everybody else. Each can have r (read), w (write) and x (execute).

Command What it does
chmod +x deploy.sh Makes a script executable
chmod 644 file Owner can read and write, others can read
chmod 755 script.sh Owner has full access, others can read and run
chown asha file Changes the owner
sudo command Runs a command as an administrator

The numbers add up: read is 4, write is 2 and execute is 1. So 7 means all three, and 5 means read and execute. Avoid chmod 777, which gives everyone full access, as a quick fix for permission errors. Find the real cause instead. And use sudo carefully, since it removes the safety checks that normally protect the system.

Processes and system information

Command What it does
ps aux Lists running processes
top or htop Shows a live view of CPU and memory
kill 1234 Asks process 1234 to stop
df -h Shows free disk space
du -sh folder Shows a folder’s size
free -h Shows memory use
systemctl status nginx Shows a service’s status
journalctl -u nginx Shows a service’s logs

To install software, use your distribution’s package manager, such as sudo apt install curl on Debian and Ubuntu, or sudo dnf install curl on Fedora and RHEL.

Archives and remote work

$ tar -czf logs.tar.gz logs
$ tar -tzf logs.tar.gz
logs/
logs/app.log

In tar, c means create, z means gzip, f names the file and t lists the contents. To extract an archive, use tar -xzf logs.tar.gz. For working with other machines, these three are what you need:

Command What it does
ssh user@server Opens a remote terminal
scp file user@server:/path/ Copies a file over SSH
curl -I https://example.com Shows a URL’s response headers

These same commands are used inside Dockerfiles and CI/CD pipelines, so this knowledge pays off across DevOps work.

Common mistakes

  • Using rm -rf without looking. Check your folder with pwd first, and be careful with spaces in paths.
  • Overwriting with >. Use >> when you meant to append.
  • Running everything with sudo. Use it only when it is required.
  • Pasting commands you do not understand. Read them first, especially anything piping a download into a shell.
  • Forgetting quotes. A file name with spaces, like "my file.txt", needs them.

Final thoughts

You do not learn the terminal by reading about it. Open a shell, make a practice folder and run each section’s commands. Then try to answer a real question using a pipe, like which error appears most often in a log. Start with navigation and files this week, add grep and pipes next, and the rest will follow as you need it.

Frequently asked questions

What are the most basic Linux commands?

Start with pwd, ls, cd, mkdir, cp, mv, rm, cat and grep. These cover moving around, managing files and searching, which makes up most everyday terminal work.

How can I practise Linux commands on Windows?

Use Windows Subsystem for Linux for a full environment, or Git Bash for the basics. Running a Linux container with Docker also works well.

What is the difference between > and >> in Linux?

A single > replaces the file’s contents with the output. A double >> adds the output to the end of the file and keeps what is already there.

Can I undo the rm command?

Generally no, because rm does not use a recycle bin. Recovery tools sometimes help but are not reliable, so keep backups and check carefully first.

What does sudo mean?

sudo runs a single command with administrator rights. It is needed for tasks such as installing software, and it should be used with care.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

LLM Structured Output Explained: Getting Reliable JSON From AI Models

LLM structured output explained with validation we ran in Pydantic: JSON mode and schemas, constrained decoding, the ways model output…

Read article →
DevOps

SSH Keys Explained: How They Work, ssh-keygen, Ed25519 and Safe Habits

SSH keys explained with keys we generated: public vs private keys, ssh-keygen, Ed25519 vs RSA, fingerprints, passphrases, ssh-agent, authorized_keys, config…

Read article →
DevOps

HTTP Caching Explained: Cache-Control, ETag and 304 Responses, With a Live Test

HTTP caching explained with a small server we ran: Cache-Control directives, max-age, no-cache vs no-store, ETag revalidation and 304 responses,…

Read article →
Test Automation

API Contract Testing Explained: Catch Breaking Changes Before They Ship

API contract testing explained with a schema check we ran: what a contract is, consumer-driven contracts, Pact, OpenAPI, which changes…

Read article →
Software Testing

Risk-Based Testing Explained: Score Risks, Build a Matrix and Test What Matters

Risk-based testing explained step by step: identifying risks, scoring likelihood and impact, building a risk matrix, mapping risk to test…

Read article →
Databases & SQL

SQL Constraints Explained: NOT NULL, UNIQUE, CHECK and FOREIGN KEY, Tested

SQL constraints explained with tests we ran: NOT NULL, UNIQUE, CHECK, DEFAULT, PRIMARY and FOREIGN KEY, the NULL loopholes, SQLite's…

Read article →
Databases & SQL

SQL Date Functions Explained: Adding, Comparing and Grouping Dates Without Bugs

SQL date functions explained with queries we ran: adding intervals, month-end surprises, date differences, the BETWEEN trap, grouping by day,…

Read article →
Software Development

Python asyncio Explained: async, await, gather and TaskGroup With Real Timings

Python asyncio explained with code we timed: coroutines, await, gather, TaskGroup, error handling, timeouts, limiting concurrency and the blocking-call mistake…

Read article →
Software Development

Debounce vs Throttle in JavaScript: How They Work, When to Use Each, Tested

Debounce vs throttle in JavaScript explained with timings we measured in Node.js: how each works, simple implementations, leading and trailing…

Read article →
Software Development

Python Context Managers Explained: The with Statement, contextlib and Real Uses

Python context managers explained with code we ran: how with works, __enter__ and __exit__, contextlib.contextmanager, suppress, ExitStack, database transactions and…

Read article →
Artificial Intelligence

LLM Temperature and Top-p Explained: How AI Models Choose Their Next Word

LLM temperature and top-p explained with a simulation we ran: how probabilities are reshaped, what top-p keeps, recommended settings by…

Read article →
DevOps

YAML Explained: Syntax, the Norway Problem and Other Traps We Tested

YAML explained with a parser test: basic syntax, lists and maps, the Norway problem, versions turning into floats, octal zip…

Read article →
DevOps

Cron Jobs Explained: Syntax, Real Schedules and the Mistakes That Break Them

Cron jobs explained with schedules we verified: the five fields, operators, real examples, the day-of-month OR day-of-week trap, environment problems,…

Read article →
Software Testing

Bug Life Cycle in Software Testing: Every Status, Who Owns It and Common Mistakes

The bug life cycle explained: every defect status from New to Closed, who owns each step, rejected, deferred and reopened…

Read article →
Test Automation

Property-Based Testing in Python: Hypothesis Finds the Bugs Your Examples Miss

Property-based testing explained with Hypothesis tests we ran: properties vs examples, strategies, shrinking, the real bugs it found in our…

Read article →
Databases & SQL

SQL Pagination Explained: OFFSET vs Keyset, With a Million-Row Test

SQL pagination explained with a million-row test we ran: LIMIT and OFFSET, why deep pages get slow, keyset (cursor) pagination,…

Read article →
Databases & SQL

SQL EXISTS vs IN: Differences, the NOT IN NULL Trap and Performance

SQL EXISTS vs IN explained with queries we ran: how each works, why NOT IN returns no rows when a…

Read article →
Software Development

Python Logging Explained: Levels, Handlers, Formatters and Mistakes to Avoid

Python logging explained with code we ran: levels, basicConfig quirks, named loggers, handlers and formatters, logger.exception, lazy formatting, duplicate logs…

Read article →
Software Development

JavaScript Map vs Object: Key Differences, Pitfalls and a Benchmark

JavaScript Map vs Object explained with code we ran in Node.js: key types, ordering, the prototype trap, JSON, size, WeakMap…

Read article →
Software Development

Python Type Hints Explained: Annotations, mypy and the Errors It Catches

Python type hints explained with a real mypy run: basic annotations, Optional and unions, TypedDict, Literal, Protocol, generics, Callable, strict…

Read article →
Artificial Intelligence

LLM Tokens Explained: How AI Models Read Text, Count Costs and Fill Context Windows

LLM tokens explained with a tokenizer we ran: how text is split, why counts differ by language and tokenizer, context…

Read article →
DevOps

Semantic Versioning Explained: MAJOR.MINOR.PATCH, Ranges and Release Rules

Semantic versioning explained with code we ran: MAJOR.MINOR.PATCH rules, pre-releases, correct version sorting, caret and tilde ranges, 0.x versions, lockfiles…

Read article →
DevOps

Git Reset vs Revert: How to Undo Commits Safely, With a Tested Example

Git reset vs revert explained with a repository we built: soft, mixed and hard reset, revert commits, reverting merges, recovering…

Read article →
Software Testing

The Test Pyramid Explained: Layers, Ratios and When to Break the Shape

The test pyramid explained: unit, integration and end-to-end layers, sensible ratios, the ice cream cone anti-pattern, the testing trophy and…

Read article →
Test Automation

pytest Fixtures Explained: Scope, yield Teardown, conftest.py and Factories

pytest fixtures explained with a suite we ran: how fixtures work, scopes, yield teardown, conftest.py, factory fixtures, parametrized fixtures, built-ins…

Read article →
Databases & SQL

SQL Upsert Explained: INSERT ON CONFLICT, MERGE and the REPLACE Trap

SQL upsert explained with queries we ran: INSERT ON CONFLICT DO UPDATE and DO NOTHING, the excluded row, conditional updates,…

Read article →
Databases & SQL

SQL LIKE Operator Explained: Wildcards, Case Sensitivity and Performance

The SQL LIKE operator explained with queries we ran: % and _ wildcards, escaping, NOT LIKE and NULL, case sensitivity…

Read article →
Artificial Intelligence

AI Hallucinations Explained: Why Language Models Make Things Up and How to Reduce It

AI hallucinations explained: what they are, why language models produce them, common types, how to reduce them with grounding and…

Read article →
Test Automation

Mocking in Python: unittest.mock, patch and the Mistakes That Make Tests Lie

Mocking in Python with unittest.mock, tested: Mock and return_value, side_effect, patching where a name is used, spec and autospec, mocking…

Read article →
Software Testing

Code Coverage Explained: Line vs Branch Coverage and What 100% Really Means

Code coverage explained with a real coverage.py run: line, branch and condition coverage, reading a report, why 100% coverage can…

Read article →
Artificial Intelligence

What Are AI Agents? How They Work, With a Simple Agent Loop You Can Run

What are AI agents? A plain guide to the agent loop, tools, memory and guardrails, with a small Python loop…

Read article →
Test Automation

TDD vs BDD: Key Differences, One Feature Built Both Ways and When to Use Each

TDD vs BDD explained with one discount feature built both ways: red-green-refactor with code we ran, Given-When-Then scenarios, tools, trade-offs…

Read article →
Software Testing

User Acceptance Testing (UAT): Process, Checklist and Real Examples

User acceptance testing explained: who runs it, how it differs from QA, a seven-step process, a UAT test case template,…

Read article →
Artificial Intelligence

What Are Embeddings? Vectors and Cosine Similarity Explained Simply

What are embeddings? A plain-language guide to vectors, cosine similarity and semantic search, with a small example we ran, common…

Read article →
Test Automation

Flaky Tests: What Causes Them and How to Fix Them for Good

Flaky tests explained with demos we ran: the main causes, how to confirm and diagnose one, proper fixes for timing,…

Read article →
Software Testing

Load Testing vs Stress Testing: Differences, Metrics and k6 Examples

Load testing vs stress testing explained: what each proves, spike and soak tests, the metrics that matter, why averages mislead,…

Read article →