DEV Community

Mayur Bodhare
Mayur Bodhare

Posted on

Linux Essentials: Basic Linux Commands Every Developer Should Know

Linux

When I first started working with Linux, the terminal looked a little intimidating.

I knew I could open folders, create files, and install applications using a graphical interface. But whenever I followed a backend development tutorial, I kept seeing commands like:

ls -la
chmod +x script.sh
ps aux
grep "ERROR" app.log
Enter fullscreen mode Exit fullscreen mode

I could copy and paste them, but I didn't really understand what they did.

And that is a problem.

As a developer, you will frequently work with Linux servers, Docker containers, cloud environments, and remote machines. Most of these environments rely heavily on the command line.

So, instead of memorizing random commands, let's learn them by understanding the problems they solve.

This article covers common Linux commands used for everyday development and server management.

Environment used in this article:

  • Operating system: GNU/Linux distributions.
  • Shell: Bash 5.x.
  • Utilities: GNU Coreutils 9.x.
  • Package management: APT for Ubuntu/Debian and DNF for Fedora/RHEL.

The commands are broadly applicable to modern Linux distributions, although some options differ between GNU and other implementations.

Table of contents

Linux essentials before commands

Before learning commands, let's understand a few basic terms.

Terminal, shell and command

People often use the words terminal, shell, and command line interchangeably.

But they are not exactly the same.

Terminal

A terminal is an application that provides a text-based interface through which you interact with your computer.

Instead of clicking buttons, you type commands.

Shell

A shell is a program that understands the commands you enter and executes them.

Examples include:

  • Bash (Bourne Again Shell).
  • Zsh (Z Shell).
  • Fish (Friendly Interactive Shell).

In this article, we'll use Bash.

Command

A command is an instruction given to the shell to perform an operation.

For example:

pwd
Enter fullscreen mode Exit fullscreen mode

This command asks the shell to execute pwd, which displays the current working directory.

Let's visualize the relationship.

          YOU
           |
           | Type command
           v
    +-------------+
    |  TERMINAL   |
    |             |
    |  pwd        |
    +-------------+
           |
           v
    +-------------+
    |    SHELL    |
    |             |
    | Understands |
    | the command |
    +-------------+
           |
           v
    +-------------+
    |  COMMAND    |
    |    pwd      |
    +-------------+
           |
           v
    +-------------+
    |   OUTPUT    |
    | /home/asha  |
    +-------------+
Enter fullscreen mode Exit fullscreen mode

Try it yourself:

echo "Hello Linux"
Enter fullscreen mode Exit fullscreen mode

Output:

Hello Linux
Enter fullscreen mode Exit fullscreen mode

echo prints the provided text to the terminal.

Behind the scenes, Bash recognizes echo as a shell command and executes it with the supplied argument.

Understanding command syntax

Most Linux commands follow a simple structure:

command [options] [arguments]
Enter fullscreen mode Exit fullscreen mode

Let's break this down.

  • Command: The operation you want to perform.
  • Options: Modify how the command behaves.
  • Arguments: Tell the command what to work on.

For example:

ls -l /home/asha
Enter fullscreen mode Exit fullscreen mode

Here:

  • ls is the command.
  • -l is an option.
  • /home/asha is the argument.

The -l option tells ls to display information in long format.

Another example:

mkdir -p projects/java
Enter fullscreen mode Exit fullscreen mode

Here:

  • mkdir creates directories.
  • -p creates parent directories if they don't exist.
  • projects/java is the directory path.

A few things to remember:

  1. Linux commands are generally case-sensitive.
  2. ls and LS are different.
  3. Options commonly start with - or --.
  4. You can often combine short options.

For example:

ls -la
Enter fullscreen mode Exit fullscreen mode

This combines:

ls -l -a
Enter fullscreen mode Exit fullscreen mode

The exact available options depend on the command.

Navigating the filesystem

The first thing you should know is how to move around the Linux filesystem.

Think of the filesystem as a hierarchy of folders and files.

/
|
+-- home
|   |
|   +-- asha
|       |
|       +-- Documents
|       |
|       +-- Downloads
|       |
|       +-- Projects
|
+-- etc
|
+-- var
|
+-- usr
|
+-- tmp
Enter fullscreen mode Exit fullscreen mode

The top-level directory / is called the root directory.

All other directories and files exist somewhere underneath it.

Before trying the commands, let's create a small practice environment.

Run:

mkdir -p ~/linux-practice/project/src
mkdir -p ~/linux-practice/project/logs

cd ~/linux-practice/project

printf 'Asha\nRavi\nMeera\n' > users.txt

printf 'INFO Order created\nERROR Payment failed\nINFO Email sent\n' > app.log

touch README.md
Enter fullscreen mode Exit fullscreen mode

We've created this structure:

project/
|
+-- src/
|
+-- logs/
|
+-- README.md
|
+-- app.log
|
+-- users.txt
Enter fullscreen mode Exit fullscreen mode

We'll use these files throughout the article.

pwd: where am I?

Imagine opening a terminal and navigating through multiple folders.

After a while, you might forget where you currently are.

How do you find your current location?

Use pwd.

pwd stands for Print Working Directory.

It displays the absolute path of the directory in which you're currently working.

Example:

pwd
Enter fullscreen mode Exit fullscreen mode

Output (example):

/home/asha/linux-practice/project
Enter fullscreen mode Exit fullscreen mode

Your username and path will be different.

Why is this useful?

Before running file-related commands, it's good to know your current location.

For example, suppose you execute:

rm app.log
Enter fullscreen mode Exit fullscreen mode

This attempts to delete app.log from your current directory.

If you are in the wrong directory, you might delete the wrong file.

That's why pwd is one of the most useful commands to remember.

Behind the scenes:

The shell maintains a current working directory for each process. The pwd utility displays that location.

ls: what is here?

Now that we know our current location, how do we see the files and folders inside it?

Use ls.

ls stands for List.

Example:

ls
Enter fullscreen mode Exit fullscreen mode

Output:

app.log  logs  README.md  src  users.txt
Enter fullscreen mode Exit fullscreen mode

We can also use different options.

1. List files in long format

ls -l
Enter fullscreen mode Exit fullscreen mode

It displays additional information such as:

  • Permissions.
  • Owner.
  • Group.
  • File size.
  • Last modification time.
  • File or directory name.

Example output (your values will differ):

-rw-r--r-- 1 asha asha  63 Nov 26 10:00 app.log
drwxr-xr-x 2 asha asha  40 Nov 26 10:00 logs
-rw-r--r-- 1 asha asha   0 Nov 26 10:00 README.md
drwxr-xr-x 2 asha asha  40 Nov 26 10:00 src
-rw-r--r-- 1 asha asha  15 Nov 26 10:00 users.txt
Enter fullscreen mode Exit fullscreen mode

2. Show hidden files

ls -a
Enter fullscreen mode Exit fullscreen mode

Output (trimmed):

.
..
app.log
logs
README.md
src
users.txt
Enter fullscreen mode Exit fullscreen mode

In Linux, filenames beginning with a dot (.) are treated as hidden by convention.

For example:

.env
.git
.bashrc
Enter fullscreen mode Exit fullscreen mode

3. Combine both options

ls -la
Enter fullscreen mode Exit fullscreen mode

This displays all entries, including hidden ones, in long format.

4. List only directory names

ls -d */
Enter fullscreen mode Exit fullscreen mode

Example output:

logs/  src/
Enter fullscreen mode Exit fullscreen mode

Behind the scenes:

ls reads directory entries and displays their names. Options control what information is shown and which entries are included.

cd: move between directories

Suppose you want to move from the project directory into src.

How do you do that?

Use cd.

cd stands for Change Directory.

Example:

cd src
Enter fullscreen mode Exit fullscreen mode

Now check your location:

pwd
Enter fullscreen mode Exit fullscreen mode

Output:

/home/asha/linux-practice/project/src
Enter fullscreen mode Exit fullscreen mode

Let's understand some useful path shortcuts.

1. Move to the parent directory

cd ..
Enter fullscreen mode Exit fullscreen mode

.. represents the parent directory.

If you're inside:

/home/asha/linux-practice/project/src
Enter fullscreen mode Exit fullscreen mode

After cd .., you move to:

/home/asha/linux-practice/project
Enter fullscreen mode Exit fullscreen mode

2. Move to your home directory

cd ~
Enter fullscreen mode Exit fullscreen mode

The ~ symbol represents your home directory.

For example:

/home/asha
Enter fullscreen mode Exit fullscreen mode

3. Move to the root directory

cd /
Enter fullscreen mode Exit fullscreen mode

This takes you to the top-level filesystem directory.

4. Return to the previous directory

cd -
Enter fullscreen mode Exit fullscreen mode

This takes you to the previous working directory.

Absolute path vs relative path

An absolute path starts from the root directory.

Example:

cd /home/asha/Documents
Enter fullscreen mode Exit fullscreen mode

A relative path starts from your current directory.

Example:

cd Documents
Enter fullscreen mode Exit fullscreen mode

The difference is simple:

  • Absolute path: Specifies the complete location.
  • Relative path: Specifies the location relative to where you currently are.

Creating and managing files

Now let's learn how to create, read, copy, move, and delete files.

These are commands you'll use almost every day.

mkdir and touch

mkdir

mkdir stands for Make Directory.

It creates a new directory.

Example:

mkdir reports
Enter fullscreen mode Exit fullscreen mode

This creates:

project/
|
+-- reports/
Enter fullscreen mode Exit fullscreen mode

What if the parent directory doesn't exist?

For example:

mkdir reports/2026/november
Enter fullscreen mode Exit fullscreen mode

This may fail because reports/2026 doesn't exist.

Use the -p option:

mkdir -p reports/2026/november
Enter fullscreen mode Exit fullscreen mode

Now all the required parent directories are created.

touch

touch creates an empty file if the file doesn't exist.

Example:

touch reports/today.txt
Enter fullscreen mode Exit fullscreen mode

The command creates:

reports/
|
+-- 2026/
|   |
|   +-- november/
|
+-- today.txt
Enter fullscreen mode Exit fullscreen mode

If the file already exists, touch normally updates its access and modification timestamps instead of clearing its contents.

Behind the scenes

These commands ask the operating system to create filesystem entries.

mkdir creates a directory, whereas touch uses the filesystem's file-creation and timestamp functionality.

cat, less, head and tail

We have created files. But how do we read their contents?

Let's use the app.log file we created earlier.

1. cat

cat is short for concatenate.

It displays file contents in the terminal.

Example:

cat app.log
Enter fullscreen mode Exit fullscreen mode

Output:

INFO Order created
ERROR Payment failed
INFO Email sent
Enter fullscreen mode Exit fullscreen mode

You can also combine multiple files:

cat users.txt app.log
Enter fullscreen mode Exit fullscreen mode

This prints the contents of both files one after another.

Use cat when the file is small.

2. less

What if the file has thousands of lines?

Displaying everything at once can become difficult.

Use less.

less app.log
Enter fullscreen mode Exit fullscreen mode

It opens the file in a pager, allowing you to scroll through its contents.

Common keys:

  • Space: Move forward one screen.
  • b: Move backward one screen.
  • /word: Search for a word.
  • q: Quit.

The visible contents in our example are:

INFO Order created
ERROR Payment failed
INFO Email sent
Enter fullscreen mode Exit fullscreen mode

3. head

What if you only want the first few lines?

Use head.

head -n 2 app.log
Enter fullscreen mode Exit fullscreen mode

Output:

INFO Order created
ERROR Payment failed
Enter fullscreen mode Exit fullscreen mode

By default, head displays the first 10 lines.

4. tail

What if you want the last few lines?

Use tail.

tail -n 2 app.log
Enter fullscreen mode Exit fullscreen mode

Output:

ERROR Payment failed
INFO Email sent
Enter fullscreen mode Exit fullscreen mode

One especially useful option is:

tail -f app.log
Enter fullscreen mode Exit fullscreen mode

This continuously displays newly appended lines as they appear.

Why is this useful?

Imagine your Spring Boot application is running on a Linux server and writing logs to application.log.

You can execute:

tail -f application.log
Enter fullscreen mode Exit fullscreen mode

Now you can observe new log entries as your application runs.

Press Ctrl + C to stop following the file.

cp and mv

Sometimes we need to copy or move files.

1. cp

cp stands for Copy.

It creates a copy of a file or directory.

Example:

cp users.txt users-backup.txt
Enter fullscreen mode Exit fullscreen mode

Now we have:

project/
|
+-- users.txt
|
+-- users-backup.txt
Enter fullscreen mode Exit fullscreen mode

To copy a directory and its contents:

cp -r src src-backup
Enter fullscreen mode Exit fullscreen mode

The -r option means recursive.

It tells cp to copy the directory contents as well.

2. mv

mv stands for Move.

It moves files or directories to another location.

Example:

mv users-backup.txt logs/
Enter fullscreen mode Exit fullscreen mode

Now the structure becomes:

project/
|
+-- users.txt
|
+-- logs/
    |
    +-- users-backup.txt
Enter fullscreen mode Exit fullscreen mode

But mv is also used for renaming files.

Example:

mv users.txt customers.txt
Enter fullscreen mode Exit fullscreen mode

Now the file is renamed to customers.txt.

What's the difference?

  • cp: Creates another copy.
  • mv: Moves or renames the original file.

rm and rmdir

Now let's learn how to delete files and directories.

1. rm

rm stands for Remove.

Example:

rm customers.txt
Enter fullscreen mode Exit fullscreen mode

This deletes the file.

You can also delete a directory and its contents using:

rm -r directory-name
Enter fullscreen mode Exit fullscreen mode

The -r option means recursive.

Be careful with this command because it can delete many files at once.

2. rmdir

rmdir removes empty directories.

Example:

mkdir empty-folder

rmdir empty-folder
Enter fullscreen mode Exit fullscreen mode

Both commands complete without output when successful.

What's the difference?

  • rmdir: Removes empty directories only.
  • rm -r: Removes directories containing files and subdirectories as well.

Important safety note

Avoid blindly executing commands such as:

rm -rf *
Enter fullscreen mode Exit fullscreen mode

The -f option forces removal without prompting for confirmation. Combined with recursive deletion, it can remove a large amount of data.

Always check your current directory using pwd before deleting anything.

Searching and inspecting data

As developers, we often work with hundreds of files and thousands of log lines.

Searching manually is not practical.

Linux provides useful commands to search and inspect information.

find: search for files

Imagine you have a project with hundreds of files.

You remember that a file named application.properties exists somewhere, but you don't know where.

Use find.

Example:

find . -name "application.properties"
Enter fullscreen mode Exit fullscreen mode

Here:

  • find is the command.
  • . means start searching from the current directory.
  • -name filters by filename.
  • "application.properties" is the filename to find.

Another example:

find . -type f -name "*.log"
Enter fullscreen mode Exit fullscreen mode

Output:

./app.log
Enter fullscreen mode Exit fullscreen mode

What does -type f mean?

It tells find to search for regular files.

Some useful options:

  • -type f: Regular files.
  • -type d: Directories.
  • -name: Case-sensitive filename matching.
  • -iname: Case-insensitive filename matching.

Example:

find . -type d -name "src"
Enter fullscreen mode Exit fullscreen mode

Output:

./src
Enter fullscreen mode Exit fullscreen mode

Behind the scenes

find traverses directories starting from the given path and evaluates the conditions you provide.

When an entry matches, it performs the requested action, which by default is printing the path.

grep: search inside files

find searches for filenames.

But what if you want to search for specific text inside files?

Use grep.

grep is commonly used to search text using patterns.

Let's search for the word ERROR in our log file.

grep "ERROR" app.log
Enter fullscreen mode Exit fullscreen mode

Output:

ERROR Payment failed
Enter fullscreen mode Exit fullscreen mode

Some useful options:

1. Show line numbers

grep -n "ERROR" app.log
Enter fullscreen mode Exit fullscreen mode

Output:

2:ERROR Payment failed
Enter fullscreen mode Exit fullscreen mode

2. Ignore uppercase and lowercase differences

grep -i "error" app.log
Enter fullscreen mode Exit fullscreen mode

Output:

ERROR Payment failed
Enter fullscreen mode Exit fullscreen mode

3. Search recursively inside directories

grep -rn "ERROR" .
Enter fullscreen mode Exit fullscreen mode

This searches files under the current directory and displays matching line numbers.

4. Count matching lines

grep -c "ERROR" app.log
Enter fullscreen mode Exit fullscreen mode

Output:

1
Enter fullscreen mode Exit fullscreen mode

Why is this useful?

Suppose your Spring Boot application is producing thousands of log entries.

Instead of opening the file and reading everything, you can search directly:

grep -n "NullPointerException" application.log
Enter fullscreen mode Exit fullscreen mode

This helps locate the lines containing the exception.

wc, sort and uniq

These commands are useful when working with text files and command output.

1. wc

wc stands for Word Count.

It can count lines, words, and bytes or characters.

Example:

wc -l users.txt
Enter fullscreen mode Exit fullscreen mode

Output:

3 users.txt
Enter fullscreen mode Exit fullscreen mode

Here, -l counts lines.

Other useful options:

  • -w: Count words.
  • -c: Count bytes.
  • -m: Count characters.

2. sort

sort arranges lines in a file.

Example:

sort users.txt
Enter fullscreen mode Exit fullscreen mode

Output:

Asha
Meera
Ravi
Enter fullscreen mode Exit fullscreen mode

By default, sorting is based on the current locale.

3. uniq

uniq removes adjacent duplicate lines.

Let's try an example:

printf 'java\nlinux\njava\n' | sort | uniq -c
Enter fullscreen mode Exit fullscreen mode

Output:

      2 java
      1 linux
Enter fullscreen mode Exit fullscreen mode

Here:

  • sort arranges identical lines next to one another.
  • uniq identifies and combines adjacent duplicate lines.
  • -c displays the number of occurrences.

Notice that uniq alone does not remove every duplicate if identical lines are separated. That's why we commonly use sort before uniq.

Getting system information

When working on a Linux server, you often need to answer questions like:

  • Which user am I logged in as?
  • What Linux version or kernel is running?
  • How much disk space is available?
  • Which processes are running?
  • How much memory is being used?

Let's explore the commands that help us answer these questions.

whoami, id, uname and hostname

1. whoami

Displays the username of the current effective user.

whoami
Enter fullscreen mode Exit fullscreen mode

Example output:

asha
Enter fullscreen mode Exit fullscreen mode

Your output will contain your username.

2. id

Displays user and group identity information.

id
Enter fullscreen mode Exit fullscreen mode

Example output (your IDs and groups will differ):

uid=1000(asha) gid=1000(asha) groups=1000(asha),27(sudo)
Enter fullscreen mode Exit fullscreen mode

This is useful when troubleshooting file access and permissions.

3. uname

Displays basic system information.

uname -s
Enter fullscreen mode Exit fullscreen mode

Output:

Linux
Enter fullscreen mode Exit fullscreen mode

To display more information:

uname -a
Enter fullscreen mode Exit fullscreen mode

Example output (version and machine details will differ):

Linux my-machine 6.x.x-generic #1 SMP x86_64 GNU/Linux
Enter fullscreen mode Exit fullscreen mode

The -a option displays all available system information.

4. hostname

Displays the machine's hostname.

hostname
Enter fullscreen mode Exit fullscreen mode

Example output:

my-linux-server
Enter fullscreen mode Exit fullscreen mode

The actual hostname depends on your machine.

ps, top and kill

Linux runs many processes in the background.

A process is a running instance of a program.

For example:

  • A browser is a process.
  • A Spring Boot application is a process.
  • A database server is a process.

Sometimes we need to inspect or stop these processes.

1. ps

ps stands for Process Status.

It displays information about running processes.

Example:

ps -ef
Enter fullscreen mode Exit fullscreen mode

This displays a detailed list of processes.

To inspect processes with a particular username:

ps -u "$USER" -f
Enter fullscreen mode Exit fullscreen mode

The output depends on which processes are running on your machine.

2. top

top displays running processes and live system information.

top
Enter fullscreen mode Exit fullscreen mode

It displays information such as:

  • CPU usage.
  • Memory usage.
  • Process IDs.
  • Running processes.
  • Process resource consumption.

Press q to exit.

Why is this useful?

Imagine your Spring Boot application is consuming too much CPU.

You can use top to identify which process is consuming resources.

3. kill

Sometimes a process becomes unresponsive.

You may need to send it a signal to stop.

The kill command sends a signal to a process using its process ID (PID).

Example:

kill 12345
Enter fullscreen mode Exit fullscreen mode

Here, 12345 is an example PID. Replace it with the actual process ID.

By default, kill sends the SIGTERM signal, which requests a graceful shutdown.

If a process refuses to stop, SIGKILL can be used as a last resort:

kill -9 12345
Enter fullscreen mode Exit fullscreen mode

Unlike SIGTERM, SIGKILL cannot be caught or ignored by the process.

Don't use it as your first option because the application does not get an opportunity to shut down cleanly.

df and du

Both commands help you understand disk usage.

But they answer different questions.

1. df

df stands for Disk Free.

It displays available and used space on mounted filesystems.

Example:

df -h
Enter fullscreen mode Exit fullscreen mode

The -h option displays sizes in human-readable units such as MB and GB.

Example output (values and mount points will differ):

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   20G   28G  42% /
Enter fullscreen mode Exit fullscreen mode

Use this when you want to know how much disk space is available on a filesystem.

2. du

du stands for Disk Usage.

It estimates the disk space used by files and directories.

Example:

du -sh ~/linux-practice/project
Enter fullscreen mode Exit fullscreen mode

Example output:

16K     /home/asha/linux-practice/project
Enter fullscreen mode Exit fullscreen mode

Your result will differ.

The options mean:

  • -s: Display only the total summary.
  • -h: Display human-readable sizes.

You can also inspect individual directories:

du -h --max-depth=1 .
Enter fullscreen mode Exit fullscreen mode

Remember the difference:

  • df: How much space is available on a filesystem?
  • du: How much space is a directory or file using?

File permissions and administrator access

One important concept in Linux is file permissions.

Not every user should be allowed to read, modify, or execute every file.

For example:

  • A normal user may read a public log file.
  • Only an administrator may modify certain system files.
  • An application script may need execute permission.

Linux provides a permission system to control these operations.

Understanding Linux permissions

Let's run:

ls -l
Enter fullscreen mode Exit fullscreen mode

You may see output like:

-rw-r--r-- 1 asha asha 15 Nov 26 10:00 users.txt
Enter fullscreen mode Exit fullscreen mode

Focus on the first part:

-rw-r--r--
Enter fullscreen mode Exit fullscreen mode

This represents file type and permissions.

Let's break it down.

-   rw-   r--   r--
|    |     |     |
|    |     |     +-- Others
|    |     |
|    |     +-------- Group
|    |
|    +-------------- Owner
|
+------------------- File type
Enter fullscreen mode Exit fullscreen mode

There are three permission types:

  • r: Read permission.
  • w: Write permission.
  • x: Execute permission.

And three permission categories:

  • Owner: The user who owns the file.
  • Group: Users belonging to the file's group.
  • Others: Everyone else.

For example:

-rw-r--r--
Enter fullscreen mode Exit fullscreen mode

Means:

  • Owner can read and write.
  • Group can only read.
  • Others can only read.

What about a directory?

Directory permissions have slightly different meanings:

  • Read (r): List directory entries.
  • Write (w): Create, delete, or rename entries, subject to other restrictions.
  • Execute (x): Access or traverse the directory.

chmod: change permissions

chmod stands for Change Mode.

It changes file or directory permissions.

Let's create a simple shell script.

printf '#!/usr/bin/env bash\necho "Hello from Linux"\n' > hello.sh
Enter fullscreen mode Exit fullscreen mode

Try executing it:

./hello.sh
Enter fullscreen mode Exit fullscreen mode

If the file does not have execute permission, you may get an error like:

bash: ./hello.sh: Permission denied
Enter fullscreen mode Exit fullscreen mode

We need to grant execute permission.

chmod u+x hello.sh
Enter fullscreen mode Exit fullscreen mode

Here:

  • chmod changes permissions.
  • u means user or owner.
  • + means add permission.
  • x means execute.

Now run:

./hello.sh
Enter fullscreen mode Exit fullscreen mode

Output:

Hello from Linux
Enter fullscreen mode Exit fullscreen mode

Numeric permissions

Linux also supports numeric permission values.

Each permission has a number:

  • Read = 4.
  • Write = 2.
  • Execute = 1.

Let's understand 755.

Owner   -> 7 -> 4 + 2 + 1 -> rwx
Group   -> 5 -> 4 + 0 + 1 -> r-x
Others  -> 5 -> 4 + 0 + 1 -> r-x
Enter fullscreen mode Exit fullscreen mode

So:

chmod 755 hello.sh
Enter fullscreen mode Exit fullscreen mode

gives the owner read, write, and execute permissions, while the group and others get read and execute permissions.

Another common example:

chmod 644 users.txt
Enter fullscreen mode Exit fullscreen mode

This gives:

  • Owner: Read and write.
  • Group: Read only.
  • Others: Read only.

sudo: run commands with elevated privileges

Sometimes normal users are not allowed to perform certain operations.

For example, installing system-wide software usually requires administrator privileges.

Linux commonly uses sudo to execute a command with elevated privileges.

Example:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

This runs the package-list update operation with administrative privileges.

You may be asked to enter your password.

Why do we need sudo?

Because modifying system-wide configuration, installing software, and managing certain services require additional permissions.

A few important points:

  • Use sudo only when necessary.
  • Understand what a command does before running it with sudo.
  • Avoid running unknown scripts as root.
  • Do not use sudo to fix every permission error.

Behind the scenes

Linux checks the current user's identity and permissions when an operation is requested.

sudo uses its configuration to authorize a command to run with elevated privileges.

Combining commands

One of the most powerful things about Linux is that we can combine simple commands to perform complex operations.

Instead of executing everything manually, we can connect commands together.

Pipes

A pipe is represented by:

|
Enter fullscreen mode Exit fullscreen mode

It takes the standard output of one command and sends it as standard input to another command.

Let's understand with an example.

Suppose we want to count how many error lines are present in our log file.

We could first search for errors and then count the results manually.

But we can combine two commands:

grep "ERROR" app.log | wc -l
Enter fullscreen mode Exit fullscreen mode

Output:

1
Enter fullscreen mode Exit fullscreen mode

What's happening?

grep "ERROR" app.log
          |
          | Matching lines
          v
       wc -l
          |
          v
     Total count
Enter fullscreen mode Exit fullscreen mode

Step by step:

  1. grep searches for the word ERROR.
  2. It prints matching lines.
  3. The pipe sends those lines to wc.
  4. wc -l counts the lines.

Another example:

ls -1 | sort
Enter fullscreen mode Exit fullscreen mode

This lists directory entries and sorts them.

Behind the scenes

Bash connects the standard output of the first command to the standard input of the next command.

This allows small utilities to work together without requiring temporary files.

Input and output redirection

Normally, a command receives input from the keyboard and sends output to the terminal.

But sometimes we want to read input from a file or save output into a file.

This is called redirection.

1. Output redirection (>)

It writes command output into a file.

Example:

echo "Hello Linux" > message.txt
Enter fullscreen mode Exit fullscreen mode

Now inspect the file:

cat message.txt
Enter fullscreen mode Exit fullscreen mode

Output:

Hello Linux
Enter fullscreen mode Exit fullscreen mode

Important: > overwrites the existing file contents.

2. Append output (>>)

What if we want to add content without overwriting the existing file?

Use >>.

echo "Welcome to Linux" >> message.txt
Enter fullscreen mode Exit fullscreen mode

Now:

cat message.txt
Enter fullscreen mode Exit fullscreen mode

Output:

Hello Linux
Welcome to Linux
Enter fullscreen mode Exit fullscreen mode

3. Input redirection (<)

It takes input from a file instead of the keyboard.

Example:

wc -l < users.txt
Enter fullscreen mode Exit fullscreen mode

Output:

3
Enter fullscreen mode Exit fullscreen mode

Notice that the filename is not displayed because the input is redirected through standard input.

4. Error redirection (2>)

Linux has separate output streams:

  • Standard input: File descriptor 0.
  • Standard output: File descriptor 1.
  • Standard error: File descriptor 2.

We can redirect errors separately.

Example:

ls missing-file 2> error.log
Enter fullscreen mode Exit fullscreen mode

The error message is stored in error.log instead of being printed to the terminal.

This is useful when running scripts or background processes.

Command chaining and exit codes

Sometimes we want to execute multiple commands in one line.

Linux provides different operators for this.

1. Semicolon (;)

Executes commands one after another, regardless of whether the previous command succeeds.

echo "First"
echo "Second"
Enter fullscreen mode Exit fullscreen mode

Equivalent chained command:

echo "First"; echo "Second"
Enter fullscreen mode Exit fullscreen mode

Output:

First
Second
Enter fullscreen mode Exit fullscreen mode

2. AND operator (&&)

Executes the next command only when the previous command succeeds.

mkdir demo && cd demo
Enter fullscreen mode Exit fullscreen mode

If directory creation succeeds, the shell changes into it.

3. OR operator (||)

Executes the next command when the previous command fails.

mkdir demo || echo "Directory creation failed"
Enter fullscreen mode Exit fullscreen mode

4. Exit status ($?)

Every command returns an exit status.

Generally:

  • 0: Success.
  • Non-zero: Failure or another status.

Example:

false
echo $?
Enter fullscreen mode Exit fullscreen mode

Output:

1
Enter fullscreen mode Exit fullscreen mode

The false command returns a non-zero status.

This is especially useful when writing shell scripts and automating tasks.

Basic networking commands

Linux is widely used on servers.

So, developers often need to inspect network interfaces, test connectivity, and make HTTP requests directly from the terminal.

ip and ping

1. ip

The ip command is used to inspect and manage network configuration.

For example:

ip addr
Enter fullscreen mode Exit fullscreen mode

Displays network interfaces and their IP addresses.

To inspect routing information:

ip route
Enter fullscreen mode Exit fullscreen mode

The output depends on your machine's network configuration.

2. ping

ping tests whether a destination can be reached using ICMP echo requests, when permitted by the network.

Example:

ping -c 4 example.com
Enter fullscreen mode Exit fullscreen mode

The -c 4 option sends four requests and stops.

The output includes:

  • Destination address.
  • Response time.
  • Packets transmitted.
  • Packets received.
  • Packet loss.

A failed ping does not always mean a server is down. Some networks block ICMP traffic.

curl and wget

Both commands are commonly used to download resources over a network.

1. curl

curl transfers data using URLs and supports protocols such as HTTP and HTTPS.

Example:

curl https://example.com
Enter fullscreen mode Exit fullscreen mode

This retrieves the response body from the URL and prints it to the terminal.

To inspect HTTP response headers:

curl -I https://example.com
Enter fullscreen mode Exit fullscreen mode

To save the response into a file:

curl -o page.html https://example.com
Enter fullscreen mode Exit fullscreen mode

2. wget

wget is commonly used to download files.

Example:

wget https://example.com
Enter fullscreen mode Exit fullscreen mode

It downloads the resource into the current directory, using the URL's filename where applicable.

Why should developers know these commands?

They are useful for:

  • Testing REST APIs.
  • Downloading files.
  • Checking HTTP response headers.
  • Debugging network connectivity.
  • Testing whether an endpoint is accessible.

For example, you can test a Spring Boot API without opening Postman:

curl http://localhost:8080/hello
Enter fullscreen mode Exit fullscreen mode

Installing software

Linux distributions use package managers to install and manage software.

A package manager handles software packages and their dependencies.

However, different distributions use different package managers.

apt and dnf

1. APT

APT stands for Advanced Package Tool.

It is commonly used on Debian-based distributions, including Ubuntu.

Some useful commands:

Update package information:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Install a package:

sudo apt install tree
Enter fullscreen mode Exit fullscreen mode

Remove a package:

sudo apt remove tree
Enter fullscreen mode Exit fullscreen mode

Search for a package:

apt search nginx
Enter fullscreen mode Exit fullscreen mode

2. DNF

DNF is commonly used on Fedora and related RPM-based distributions.

Install a package:

sudo dnf install tree
Enter fullscreen mode Exit fullscreen mode

Remove a package:

sudo dnf remove tree
Enter fullscreen mode Exit fullscreen mode

Search for a package:

dnf search nginx
Enter fullscreen mode Exit fullscreen mode

Which one should you use?

  • Ubuntu and Debian: APT.
  • Fedora: DNF.
  • Other distributions: Check the package manager used by that distribution.

Do not blindly execute APT commands on Fedora or DNF commands on Ubuntu.

Archives and file types

When working with applications, we often need to package files, inspect file types, and locate executable programs.

tar, file and which

1. tar

tar is used to create and extract archive files.

For example, let's create a compressed archive of our project directory.

Move to the parent directory:

cd ~/linux-practice
Enter fullscreen mode Exit fullscreen mode

Create a compressed archive:

tar -czf project-backup.tar.gz project
Enter fullscreen mode Exit fullscreen mode

Let's understand the options:

  • c: Create an archive.
  • z: Compress using gzip.
  • f: Specify the archive filename.

To view the files inside the archive:

tar -tzf project-backup.tar.gz
Enter fullscreen mode Exit fullscreen mode

Example output:

project/
project/logs/
project/README.md
project/src/
project/users.txt
project/app.log
Enter fullscreen mode Exit fullscreen mode

To extract the archive:

tar -xzf project-backup.tar.gz
Enter fullscreen mode Exit fullscreen mode

The x option extracts the archive.

2. file

Sometimes the filename extension does not tell us the actual file type.

The file command identifies a file by inspecting its contents.

Example:

file project/app.log
Enter fullscreen mode Exit fullscreen mode

Output:

project/app.log: ASCII text
Enter fullscreen mode Exit fullscreen mode

This is useful when dealing with unknown files.

3. which

which is commonly used to locate an executable through the directories listed in the PATH environment variable.

Example:

which bash
Enter fullscreen mode Exit fullscreen mode

Example output:

/usr/bin/bash
Enter fullscreen mode Exit fullscreen mode

A useful alternative is:

command -v bash
Enter fullscreen mode Exit fullscreen mode

command -v is a shell builtin and is generally preferable when checking how the current shell resolves a command.

Getting help

You don't need to memorize every command and every option.

Linux provides built-in ways to learn about commands.

man and --help

1. man

man stands for Manual.

It displays the manual page of a command.

Example:

man ls
Enter fullscreen mode Exit fullscreen mode

This opens the manual for ls.

You can read about:

  • Description.
  • Syntax.
  • Available options.
  • Examples.
  • Related commands.

Press q to exit.

2. --help

Many commands provide a shorter help message through --help.

Example:

ls --help
Enter fullscreen mode Exit fullscreen mode

This displays available options and basic usage information.

3. history

Want to see commands you previously executed?

Use:

history
Enter fullscreen mode Exit fullscreen mode

It displays the command history available in the current shell session and history file, depending on shell configuration.

4. clear

Is your terminal full of command output?

Use:

clear
Enter fullscreen mode Exit fullscreen mode

It clears the visible terminal screen.

These commands are useful because you can learn directly from your Linux environment rather than depending on tutorials for every option.

Which commands should I learn first?

We've covered a lot of commands.

But as a beginner, you don't need to memorize all of them on day one.

Start with the commands you'll use most frequently.

First priority: Navigation

  • pwd: Find your current location.
  • ls: List files and directories.
  • cd: Move between directories.

Second priority: File management

  • mkdir: Create directories.
  • touch: Create empty files.
  • cat: Display file contents.
  • cp: Copy files.
  • mv: Move or rename files.
  • rm: Delete files.

Third priority: Searching and logs

  • find: Search for files.
  • grep: Search inside files.
  • head: Display the first lines.
  • tail: Display the last lines.
  • less: Read large files.
  • wc: Count lines and words.

Fourth priority: System management

  • ps: Inspect processes.
  • top: Monitor processes.
  • kill: Send signals to processes.
  • df: Check filesystem space.
  • du: Check directory space.
  • chmod: Change permissions.
  • sudo: Execute authorized administrative commands.

Fifth priority: Developer productivity

  • curl: Test HTTP endpoints.
  • tar: Create and extract archives.
  • ssh: Connect to remote machines.
  • ip: Inspect network configuration.
  • man: Read command documentation.

These commands form a good foundation for working with Linux as a backend developer.

Common mistakes

Here are six mistakes beginners commonly make when using Linux commands.

  1. Confusing absolute and relative paths: /home/asha/project is an absolute path, whereas project is relative to the current directory. Always check your location using pwd.

  2. Ignoring case sensitivity: README.md, Readme.md, and readme.md are different filenames. Type names exactly as they appear.

  3. Using rm without checking the path: rm does not normally move files into a recycle bin. Check the target using pwd and ls before deleting anything.

  4. Using sudo for every command: Administrative privileges should be used only when required. Understand why a command needs elevated permissions.

  5. Assuming uniq removes every duplicate: uniq removes adjacent duplicate lines. Use sort before uniq when you want to group identical lines.

  6. Ignoring command output and exit status: A command that prints nothing may have succeeded, while a non-zero exit status generally indicates failure. Check the output and use echo $? when debugging.

Quick recap

Let's quickly revise the commands we've covered.

Navigation

  • pwd: Print current working directory.
  • ls: List directory contents.
  • cd: Change directory.

File and directory management

  • mkdir: Create directories.
  • touch: Create empty files or update timestamps.
  • cat: Display file contents.
  • less: Read files interactively.
  • head: Display the first lines.
  • tail: Display the last lines.
  • cp: Copy files.
  • mv: Move or rename files.
  • rm: Remove files and directories.
  • rmdir: Remove empty directories.

Searching and text processing

  • find: Search for files and directories.
  • grep: Search text.
  • wc: Count lines, words, and bytes.
  • sort: Sort lines.
  • uniq: Remove adjacent duplicate lines.

System management

  • whoami: Display current effective username.
  • id: Display user and group information.
  • uname: Display system information.
  • hostname: Display machine hostname.
  • ps: Display process information.
  • top: Monitor running processes.
  • kill: Send signals to processes.
  • df: Display filesystem space.
  • du: Display directory and file usage.
  • chmod: Change file permissions.
  • sudo: Execute authorized commands with elevated privileges.

Networking and utilities

  • ip: Inspect network configuration.
  • ping: Test network reachability using ICMP.
  • curl: Transfer data using URLs.
  • wget: Download resources.
  • tar: Create and extract archives.
  • file: Identify file types.
  • which: Locate executables in PATH.
  • man: Read manual pages.
  • history: Display command history.
  • clear: Clear the visible terminal.

Try it yourself

Practice idea:

Create a directory named linux-practice and build this structure:

linux-practice/
|
+-- backend/
|   |
|   +-- src/
|   |
|   +-- logs/
|       |
|       +-- application.log
|
+-- frontend/
|
+-- README.md
|
+-- users.txt
Enter fullscreen mode Exit fullscreen mode

Then perform these operations:

  1. Navigate into the backend directory.
  2. Display its absolute path.
  3. List all files, including hidden files.
  4. Create a file named application.properties inside src.
  5. Add some text to application.log.
  6. Search the log file for the word ERROR.
  7. Display the last two lines of the log.
  8. Copy users.txt to users-backup.txt.
  9. Change the permission of a shell script to make it executable.
  10. Create a compressed archive of the entire project.

Bonus experiment:

Imagine you have deployed a Spring Boot application on a Linux server.

Try answering these questions using only terminal commands:

  • Which user is running the application?
  • Which process is using port 8080?
  • How much disk space is available?
  • How can you watch application logs in real time?
  • How can you find NullPointerException occurrences in the logs?
  • How can you stop a process gracefully?

The goal is not to memorize commands. It's to understand what problem each command solves and become comfortable combining them.

If this helped, or if you spotted something I should fix, tell me in the comments. I'm still learning too.

Top comments (0)