Essential Linux Terminal Commands with Examples

Essential Linux terminal commands cover a small set of everyday jobs: locating files, moving between directories, reading text, copying documents and checking what your computer is doing. Learn those jobs first. Memorising a hundred command names can wait.

The examples below describe the command, its useful options and the files or directories it acts on. Practise with disposable files inside your home directory, not system configuration files or your only copy of an assignment. Most routine file work needs no administrator access.

The focus is interactive use in Bash and common Linux utilities. Other shells and utility implementations can differ, so check the help installed on your own machine before relying on an unfamiliar option.

Read a Command Before Running It

A terminal is the application that displays your session. The shell interprets your input and starts programs. Some commands, including cd, are built into the shell; others are separate programs.

A simple command usually contains three parts: a command name, options that change its behaviour, and arguments identifying its input or destination. With ls, the command requests a directory listing. The option -l requests a detailed listing, while a directory argument identifies what to list.

Options are not a universal language. The same letter can mean different things in different programs. Short options commonly start with one hyphen; long options commonly start with two. Some commands combine short options, but do not assume every program accepts that arrangement.

Spaces normally separate arguments. A filename such as Annual Report.txt therefore needs protection so the shell treats it as one name. Straight single or double quotation marks can protect spaces, although their treatment of variables and other characters differs. The Bash manual’s quoting rules cover those distinctions. Curly quotation marks copied from formatted documents are not substitutes.

Also distinguish the prompt from your input. Tutorials sometimes show a dollar sign before a command to represent a regular user’s prompt. That symbol is generally not something to type. A hash sign often represents a root prompt, but prompts are customisable and should not be your only check of identity.

A Short Reference for Everyday Tasks

Task Commands to recognise Main consideration
Check your location pwd, ls, cd Relative paths depend on the current directory.
Create directories and empty files mkdir, touch Touch also changes timestamps on existing files.
Copy, move and rename cp, mv An existing destination may be overwritten.
Remove files and directories rm, rmdir Removal is not a trip to the desktop trash.
Read text cat, less, head, tail Choose a viewer that suits the file’s size.
Search grep, find Searching contents and searching filenames are different jobs.
Measure and organise text wc, sort, uniq Line counts, word counts and duplicate handling have different rules.
Inspect the system df, du, free, ps, top Inspect before deleting files or stopping processes.

Find Your Location with pwd, ls and cd

pwd: Display the current directory

pwd prints your working directory. If you are working inside a directory named Documents under the home directory /home/alex, the result may be /home/alex/Documents.

This matters because many commands interpret filenames relative to that location. A request to copy notes.txt refers to a file in the current directory unless you supply another path. Before a move or removal, checking your location is a useful habit.

ls: Inspect directory contents

ls lists entries in a directory. With no directory argument, it lists the current one. Give it the path to Downloads when you want to inspect that directory without moving there.

The -l option provides a longer listing, including permissions, ownership, size and a timestamp. The -a option includes names beginning with a dot, which are normally hidden from the default listing. The -h option makes sizes easier to read when used with a size-displaying format such as the long listing.

Do not rely entirely on colours to identify directories or executable files. Colour settings vary. The detailed listing provides more useful evidence, especially when troubleshooting permissions or checking whether a destination already exists.

cd: Change directories

cd changes the shell’s current directory. Give it Documents to enter a child directory with that name. The path .. refers to the parent directory, while . refers to the current directory.

With no argument, cd normally returns to your home directory. A single hyphen as its argument returns to the previous working directory, which is convenient when switching between two locations.

An absolute path starts at /, the root directory. A relative path starts from your current location. The tilde character commonly represents your home directory in shell input. Our guide to the Linux filesystem and directory structure covers where personal files, configuration and system data belong.

Filename case also matters on typical Linux filesystems. Documents and documents can identify different directories. Use the spelling shown by the directory listing rather than guessing.

Create Files and Directories with mkdir and touch

mkdir creates directories. For practice, create a directory named terminal-practice inside your home directory and keep experimental files there. That gives you a clear boundary between learning material and files you care about.

The -p option creates missing parent directories along a path. If your intended directory is projects/demo/notes, that option allows the missing directories above notes to be created too. Without it, a missing parent directory causes an error.

touch can create an empty file when the named file does not exist. Naming a new file notes.txt gives you something harmless to inspect, copy and rename.

However, file creation is not its only job. For an existing file, touch normally updates its access and modification timestamps without replacing its contents. Do not use it casually on files whose timestamps matter to a build process or an investigation.

Successful commands do not always print a message. After creating a directory or file, use ls to check the result. A quiet terminal can mean the operation completed normally, not that nothing happened.

Copy, Move and Rename Files with cp and mv

cp: Make another copy

cp copies files. For a simple example, identify notes.txt as the source and notes-copy.txt as the destination. The original remains in place and another file appears under the destination name.

The destination changes the result. If it is an existing directory, the copied file normally goes inside that directory using its original filename. If it names a file, that name becomes the copy’s name.

Check existing destinations before copying. A copy operation can overwrite a file without asking under ordinary defaults. The -i option requests confirmation before an overwrite. Read the question carefully; responding automatically defeats the point.

Copying a directory requires recursive handling. The -R option includes its contents and subdirectories. For a practice directory, inspect both the source and destination afterwards so you can see whether you copied the directory itself or placed it inside another directory.

A second copy on the same computer can help with a quick edit, but it is not a complete backup plan. Disk failure, theft or an accidental operation affecting both copies can still remove your safety net. Use a separate recovery process for valuable data.

mv: Move or rename

mv handles both moving and renaming. Giving notes-copy.txt a new destination name of meeting-notes.txt renames it when both paths refer to the same directory.

Giving an existing directory as the destination moves the file into that directory. Again, inspect the destination first: mv can replace an existing file. Its -i option requests an overwrite confirmation.

After moving files, verify their new location before continuing. This is especially useful when two directories contain similarly named documents. Avoid combining a large reorganisation with deletion until you have checked what moved and what remained.

Remove Files Carefully with rm and rmdir

rmdir removes empty directories. It refuses to remove a directory containing files, making it a useful choice when your intention is simply to tidy away an empty folder.

rm removes named files. It does not normally send them to your desktop’s trash, and there is no general undo command to reverse it. Treat removal as permanent even though recovery may sometimes be possible.

For GNU rm, -i requests confirmation for each removal. The -r or -R option removes directories and their contents recursively. The -f option suppresses prompts and ignores missing files. The GNU rm documentation details these behaviours. A force option does not make deletion safer; it removes opportunities to reconsider.

Before deleting anything, check the working directory, inspect the target and confirm that its path names exactly what you intend. Avoid wildcard removal while learning. A short pattern can select far more files than its appearance suggests.

Practise by removing one disposable copy, then confirm that the original remains. For important documents, establish desktop backups and a restoration process before experimenting with bulk operations. A confirmation prompt is a checkpoint, not a backup.

Read Text Files with cat, less, head and tail

cat: Display short text files

cat writes file contents to standard output, normally your terminal. It works well for a short note, a small configuration file you are permitted to read, or a brief report.

For example, giving it the path to your practice notes displays the text without opening an editor. If you provide several files, their contents appear one after another. The command does not add explanatory headings between them by default.

Avoid using cat as a general viewer for unknown files. Images, archives and other binary formats are not useful as terminal text. Large text files can also bury the information you wanted beneath pages of output.

less: Browse without printing everything at once

less is a pager: it lets you move through text a screen at a time. Use it for a longer report or log file rather than sending the entire file straight to the terminal.

Common controls include Space to move forward, b to move back, and q to quit. A forward slash starts a search; enter the search text and press Enter. These controls belong to the pager, not your shell.

When watching a growing file, the F command follows new content as it arrives. The less project’s usage FAQ covers following files and other viewing options. Start with ordinary browsing before adding custom settings.

head and tail: Inspect the beginning or end

head displays the beginning of a file, while tail displays the end. Both commonly show ten lines by default. Their -n option lets you request another line count.

For a large exported text file, inspecting the first twenty lines can reveal headings and formatting without opening everything. For an application log, the last fifty lines may contain the most recent activity.

The -f option makes tail follow a file as it grows. Press Ctrl + C to interrupt it when finished. For services whose logs are stored in the systemd journal, use the separate workflow for troubleshooting with journalctl rather than assuming every service has a plain text log file.

Find Text with grep and Files with find

grep: Search inside files

grep selects lines matching a search pattern. Think of it as a way to answer “Which lines mention this?” rather than “Where is this file?”

Suppose a practice report contains several lines mentioning a deadline. Give grep the search text and the report’s path to display matching lines. The -n option adds line numbers, making it easier to locate each match in an editor.

The -i option ignores letter case. The -F option treats the search text as fixed strings rather than regular expressions, which is useful for literal text containing punctuation. These options are defined in the Open Group specification for grep.

For example, a literal search for report.txt is different from interpreting the dot as part of a regular expression. Choose fixed-string matching when you mean the actual characters rather than a pattern language.

No matching output does not automatically mean something broke. The file may contain no match, the search may use different capitalisation, or you may have selected the wrong file. Check those possibilities before broadening the search.

find: Search directory trees

find walks through a directory tree and tests entries against conditions. Start with the smallest useful directory, such as Documents, rather than searching the entire computer.

A name test can select filenames matching a pattern such as *.txt. A type test can restrict results to regular files rather than directories. The Open Group specification for find defines its recursive search model and filename tests.

Protect a filename pattern with straight quotation marks when passing it to find. Otherwise, your shell may expand it against files in the current directory before the search program receives it.

Keep your first searches read only: display the matching paths and inspect them. Do not add deletion or automatic execution just because a copied example contains it. Finding the wrong set of files is inconvenient; modifying that set creates a different problem.

Count and Organise Text with wc, sort and uniq

wc reports counts. Its -l option counts newline characters, -w counts words, and -c counts bytes. The -m option counts characters, which can differ from bytes in text using multibyte encodings.

For a list containing one entry on each newline-terminated line, a line count gives a quick estimate of the number of entries. Do not treat it as a universal record counter: a missing final newline or a structured format with multiline records changes the interpretation.

sort orders text lines. Its default ordering is not the same as sorting numbers by value. Use the numeric option -n when your practice file contains plain numeric values that should be compared numerically.

uniq handles adjacent repeated lines. If identical lines appear in different parts of a file, they are not adjacent and will not all be collapsed by a simple pass. Sorting first is a common way to bring identical lines together, provided you do not need to preserve the original order.

Start with a small sample whose correct result you can work out yourself. Text tools are easier to trust when you have checked their behaviour on five lines before applying them to fifty thousand.

Check Storage, Memory and Processes

df and du: Separate filesystem capacity from directory usage

df reports space usage for mounted filesystems. Use it when the question is whether a filesystem is running out of space. Its -h option presents sizes in more readable units.

du estimates space used by files and directories. Use it when the question is which directory is consuming that space. The -s option requests a summary for each named argument rather than a long breakdown.

For example, inspect the filesystem containing your home directory with df, then measure Downloads with du. These answer related but different questions. Do not expect a directory total to equal the usage of the whole filesystem.

Permissions, filesystem accounting and files outside the directory you measured can affect what you see. For a fuller investigation, use the guide to monitoring Linux CPU, memory, disk and network usage.

free, ps and top: Inspect resource use

free displays memory and swap information. On typical Linux systems, its available-memory figure is more useful for assessing room for applications than the unused-memory figure alone. Memory used for cache is not automatically evidence of a problem.

ps provides a snapshot of processes. Its default view is narrower than many beginners expect, so consult its help when you need processes beyond the current terminal session.

top provides a regularly refreshed process display. Use it to observe activity before deciding that an application is stuck. A brief CPU spike during an update or file import is not the same as sustained unexplained load.

kill: Send a signal, not necessarily a forced stop

kill sends a signal to a process identified by its process ID. Its default TERM signal requests termination, allowing an application to handle the request. The procps kill manual documents the default and other signal choices.

Try the application’s normal exit control first. If a signal is necessary, verify the process ID and owner immediately beforehand. Forced termination can lose unsaved work, and stopping a system process without knowing its role can disrupt other tasks.

Recognise Permissions and Administrator Access

whoami displays your effective username. id provides user and group identity information. These are useful checks when a terminal session behaves differently from your desktop session or when working on another machine.

chmod changes permission bits. A sensible beginner example is adding execute permission for the owner of a script you created and inspected. That is different from granting every user permission to read, change and execute everything in a directory.

Avoid blanket permission changes as a response to an error. Directory permissions, file ownership and access through parent directories all matter. The guide to Linux file permissions and ownership explains those relationships without reducing every problem to “make it writable”.

sudo runs an authorised command as another user, commonly root. It is not a repair option for failed commands. If a copy operation inside your home directory reports a permissions error, investigate the paths and ownership before increasing privileges.

Authentication behaviour depends on local policy. A password prompt may show no characters as you type. That alone does not mean the terminal has frozen.

Routine viewing, navigation and practice-file management should normally work as your regular user. Reserve administrator access for tasks that actually require it, and review Linux users, groups and sudo access before changing account permissions.

Get Help and Interpret Common Errors

man, help and type

man opens an installed manual page. Give it a command name to read the description, options and documented behaviour. Manual pages can be terse, but the option descriptions answer questions that short online examples often leave out.

In Bash, help documents shell builtins. It is particularly useful for commands such as cd, whose behaviour belongs to the shell rather than a separate executable.

type tells you how Bash resolves a command name. This can reveal that a familiar name refers to an alias, function, builtin or executable file. It helps explain why your session behaves differently from an example written for another environment.

Many external commands also accept --help, but this is not universal. Check local documentation rather than assuming that every program shares the same help option.

Command not found

This usually means the shell could not resolve the command name. Check spelling, then whether the program is installed and available through the shell’s command search path. A program being installed somewhere does not necessarily make its name available in every session.

Do not respond by downloading a random installer. Use your distribution’s supported software sources and the appropriate tool described in APT, DNF and Pacman package management. Package names do not always match command names.

No such file or directory

Check the path, capitalisation and current directory. A removable drive may also be absent or mounted somewhere other than expected. Repeating the same command with administrator access does not correct a misspelled filename.

Permission denied

Check who owns the file, its permissions and whether you can access its parent directories. If the operation concerns a managed service rather than a personal file, follow the appropriate systemd service-management workflow instead of editing or stopping unrelated files and processes.

Use Completion and History Without Repeating Mistakes

In a typical Bash session, Tab attempts to complete command names and paths. Start typing a directory name and use completion to reduce spelling errors. If several names match, you may need to provide more characters or request a list of possibilities.

The Up arrow recalls previous input. In Bash’s usual Emacs editing mode, Ctrl + R searches backward through command history. These are editing aids, not checks that an old command remains appropriate.

Always review recalled input before running it. Your working directory, destination files and connected drives may have changed since the previous attempt. History remembers the text, not whether repeating it is sensible.

Keep passwords, access tokens and other secrets out of command arguments wherever possible. Command history and process inspection can expose more than expected. Clearing the screen is cosmetic; it does not remove those records.

Practise a Complete File Workflow

A short sequence of tasks builds better habits than collecting unrelated commands. Keep this exercise inside the disposable practice directory you created earlier.

  1. Confirm the location. Use pwd and inspect the directory with ls before changing anything.
  2. Create practice material. Make a child directory with mkdir and an empty note with touch. Add a few lines using a text editor.
  3. Inspect and search. Read the note with cat or less, locate a word with grep, and check its line count with wc.
  4. Copy and rename. Make a copy with cp, rename that copy with mv, and verify that both intended files exist.
  5. Remove only the disposable copy. Check its full path, remove it with an interactive confirmation, then inspect the directory again.

Once those operations feel predictable, learn how commands pass output to one another. A pipe connects one command’s output to another command’s input; redirection sends output elsewhere, often to a file. Be careful: ordinary output redirection can truncate an existing destination before the command does its work.

The next step is Linux pipes, redirection and command chaining. Build those combinations from commands you already understand. A readable command you can explain is more useful than a clever one you are afraid to change.