DEV Community

Cover image for Learning Linux? Don't Start by Memorising Commands
Snigdha Chaudhari
Snigdha Chaudhari

Posted on

Learning Linux? Don't Start by Memorising Commands

When I first started learning Linux, I thought I needed to remember a lot of commands.

ps, top, systemctl, journalctl, chmod, chown, grep, find...

The list kept growing.

But knowing what a command does is not always the same as knowing when to use it.

I could read that journalctl shows logs, but that didn't automatically tell me why I should check logs when a service fails. I knew chmod changes permissions, but that made much more sense once I actually saw a script return Permission denied.

What helped was connecting the commands to the things happening on the system.

A process is running. A service manages it. Logs help explain what happened. Files and configuration live in different parts of the filesystem. Permissions and ownership decide who can access them.

Once those pieces started connecting, the commands stopped feeling like random things I had to memorise.

So if you're learning Linux too, these are the things worth understanding first.


First, understand what's happening underneath

You don't need to go extremely deep into Linux internals at the beginning. But understanding a few basic pieces makes everything else easier.

A simplified view looks like this:

Applications
     ↓
Shell
     ↓
Kernel
     ↓
Hardware
Enter fullscreen mode Exit fullscreen mode

The hardware is the physical machine: CPU, memory, storage and network interfaces.

The kernel is the core of Linux. It handles things like:

  • Processes
  • Memory
  • File systems
  • Communication with hardware

The shell is where you interact with the system using commands.

When you run:

ls
Enter fullscreen mode Exit fullscreen mode

the shell interprets your command and asks the operating system to perform the required action.

So a simple way to think about it is:

You → Shell → Linux
Enter fullscreen mode Exit fullscreen mode

That is already more useful than just memorising what ls does.


A program running is a process

A process is simply a program that is currently running.

Each process has a unique Process ID, or PID.

To see running processes:

ps aux
Enter fullscreen mode Exit fullscreen mode

This is useful when you want to answer:

What's running on this machine?

If the system feels slow, you probably want to know which process is using resources.

For that:

top
Enter fullscreen mode Exit fullscreen mode

top gives you a live view of processes along with CPU and memory usage.

To find a specific process:

ps aux | grep nginx
Enter fullscreen mode Exit fullscreen mode

And if you already know the PID and want more details:

ps -p <PID> -o pid,ppid,command
Enter fullscreen mode Exit fullscreen mode

This can help you see:

  • The process ID
  • Its parent process
  • The command used to start it

If a process needs to be stopped:

kill <PID>
Enter fullscreen mode Exit fullscreen mode

And if it refuses to stop:

kill -9 <PID>
Enter fullscreen mode Exit fullscreen mode

But force-stopping a process should not be the first thing you do. First understand what the process is and why it's running.


A service is not quite the same thing as a process

This was one of the concepts that helped things connect.

A process is something currently running.

A service is a program that the operating system manages.

For example, Nginx runs as one or more processes, but you usually manage it as a service.

On Linux systems using systemd, that means you can check its status:

systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

Start it:

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

Restart it:

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Enable it to start automatically after a reboot:

sudo systemctl enable nginx
Enter fullscreen mode Exit fullscreen mode

And check whether it is enabled:

systemctl is-enabled nginx
Enter fullscreen mode Exit fullscreen mode

The difference between these two is worth remembering:

start  → start the service now
enable → start the service automatically during boot
Enter fullscreen mode Exit fullscreen mode

So if a web server isn't working, systemctl status nginx is often a much better starting point than randomly trying commands.


If something breaks, check what happened

This is where logs come in.

A service might fail because of:

  • A bad configuration
  • Missing files
  • Port conflicts
  • Permission issues
  • Dependency problems

Instead of guessing, check the logs.

For a service managed by systemd:

journalctl -u nginx
Enter fullscreen mode Exit fullscreen mode

To see the latest entries:

journalctl -u nginx -n 50
Enter fullscreen mode Exit fullscreen mode

To watch logs live:

journalctl -u nginx -f
Enter fullscreen mode Exit fullscreen mode

Or to check recent activity:

journalctl -u nginx --since "10 min ago"
Enter fullscreen mode Exit fullscreen mode

For normal log files:

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

The important thing isn't memorising all the journalctl options.

It's remembering:

Service has a problem? Check its status. Then check its logs.

That simple flow already covers a lot of basic troubleshooting.


Know where to look

Linux has a standard filesystem structure, and knowing a few important locations can save you a lot of time.

Everything starts from:

/
Enter fullscreen mode Exit fullscreen mode

Some directories you'll run into often are:

/home      → User home directories
/root      → Root user's home directory
/etc       → System and application configuration
/var/log   → Logs
/tmp       → Temporary files
/bin       → Essential commands
/usr/bin   → Common system commands and utilities
/opt       → Optional or third-party software
Enter fullscreen mode Exit fullscreen mode

You don't need to memorise the entire filesystem hierarchy.

But knowing that:

  • configuration is often in /etc
  • logs are often in /var/log
  • user files are usually under /home

gives you a much better starting point when investigating something.

To see where you currently are:

pwd
Enter fullscreen mode Exit fullscreen mode

To move around:

cd /var/log
Enter fullscreen mode Exit fullscreen mode

To move back one directory:

cd ..
Enter fullscreen mode Exit fullscreen mode

To list files:

ls
Enter fullscreen mode Exit fullscreen mode

For more details:

ls -l
Enter fullscreen mode Exit fullscreen mode

And to include hidden files:

ls -la
Enter fullscreen mode Exit fullscreen mode

Disk full? Don't guess—find out what's using it

A server running out of disk space is a common problem.

First, check the available disk space:

df -h
Enter fullscreen mode Exit fullscreen mode

If you need to see how much space files or directories are using:

du -sh *
Enter fullscreen mode Exit fullscreen mode

And if you suspect logs are growing:

du -sh /var/log/* 2>/dev/null | sort -h | tail -5
Enter fullscreen mode Exit fullscreen mode

This checks the sizes of entries inside /var/log, sorts them, and shows the largest ones.

Again, the command is easier to remember when you connect it to the question:

What's using my disk space?


Files: create them, read them, change them

Creating a file:

touch notes.txt
Enter fullscreen mode Exit fullscreen mode

Creating a directory:

mkdir projects
Enter fullscreen mode Exit fullscreen mode

Creating nested directories:

mkdir -p project/app/logs
Enter fullscreen mode Exit fullscreen mode

To read a file:

cat notes.txt
Enter fullscreen mode Exit fullscreen mode

For a large file:

less notes.txt
Enter fullscreen mode Exit fullscreen mode

To see the first few lines:

head -n 5 notes.txt
Enter fullscreen mode Exit fullscreen mode

To see the last few:

tail -n 5 notes.txt
Enter fullscreen mode Exit fullscreen mode

One small thing that is easy to forget:

echo "Hello" > notes.txt
Enter fullscreen mode Exit fullscreen mode

> writes to the file by replacing its existing content.

But:

echo "Hello" >> notes.txt
Enter fullscreen mode Exit fullscreen mode

adds the content to the end.

A simple reminder:

>   = overwrite
>>  = append
Enter fullscreen mode Exit fullscreen mode

You can also use:

echo "Hello" | tee -a notes.txt
Enter fullscreen mode Exit fullscreen mode

This writes to the file while also showing the output on the screen.


Permissions explain a lot of "Permission denied" errors

Linux permissions are based on three things:

r → read
w → write
x → execute
Enter fullscreen mode Exit fullscreen mode

These permissions are applied to:

Owner | Group | Others
Enter fullscreen mode Exit fullscreen mode

You can check them using:

ls -l
Enter fullscreen mode Exit fullscreen mode

For example:

-rwxr-xr-x
Enter fullscreen mode Exit fullscreen mode

can be read as:

Owner   → rwx
Group   → r-x
Others  → r-x
Enter fullscreen mode Exit fullscreen mode

Permissions can be changed using chmod.

To make a script executable:

chmod +x script.sh
Enter fullscreen mode Exit fullscreen mode

To remove write permission:

chmod -w file.txt
Enter fullscreen mode Exit fullscreen mode

You can also use numeric permissions.

The values are:

read    = 4
write   = 2
execute = 1
Enter fullscreen mode Exit fullscreen mode

So:

chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode

means:

7 → read + write + execute
5 → read + execute
5 → read + execute
Enter fullscreen mode Exit fullscreen mode

This becomes easier to understand when you actually see the result.

A script without execute permission:

./script.sh
Enter fullscreen mode Exit fullscreen mode

can return:

Permission denied
Enter fullscreen mode Exit fullscreen mode

Add execute permission:

chmod +x script.sh
Enter fullscreen mode Exit fullscreen mode

and it can run again.

That one error teaches more about chmod than memorising the command definition ever will.


Permissions and ownership are different

This is another important distinction.

Permissions answer:

What can people do with this file?

Ownership answers:

Who does this file belong to?

Every Linux file has an owner and a group.

You can check both using:

ls -l
Enter fullscreen mode Exit fullscreen mode

For example:

-rw-rw-r-- 1 ubuntu developers file.txt
Enter fullscreen mode Exit fullscreen mode

Here:

Owner → ubuntu
Group → developers
Enter fullscreen mode Exit fullscreen mode

To change the owner:

sudo chown username file.txt
Enter fullscreen mode Exit fullscreen mode

To change only the group:

sudo chgrp groupname file.txt
Enter fullscreen mode Exit fullscreen mode

To change both:

sudo chown username:groupname file.txt
Enter fullscreen mode Exit fullscreen mode

For an entire directory and everything inside it:

sudo chown -R username:groupname directory/
Enter fullscreen mode Exit fullscreen mode

The -R means recursive.

The easiest way to remember these commands is:

chmod → changes permissions
chown → changes owner
chgrp → changes group
Enter fullscreen mode Exit fullscreen mode

And after making changes:

ls -l
Enter fullscreen mode Exit fullscreen mode

Always verify.


Don't just run commands. Verify what changed.

One thing that kept coming up while practising Linux was this:

Running a command doesn't mean the job is finished.

If you start a service:

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

check:

systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

If you change permissions:

chmod +x script.sh
Enter fullscreen mode Exit fullscreen mode

check:

ls -l script.sh
Enter fullscreen mode Exit fullscreen mode

If you change ownership:

sudo chown user:group file.txt
Enter fullscreen mode Exit fullscreen mode

check:

ls -l file.txt
Enter fullscreen mode Exit fullscreen mode

A good habit is:

Change something
      ↓
Check the result
      ↓
Test that it works
Enter fullscreen mode Exit fullscreen mode

That habit is useful far beyond Linux.


The commands I would remember first

If I had to reduce everything down to a small set, I wouldn't try to remember commands alphabetically.

I'd remember them by the questions they help answer.

What's running?

ps aux
top
Enter fullscreen mode Exit fullscreen mode

Is the service healthy?

systemctl status <service>
Enter fullscreen mode Exit fullscreen mode

Why did the service fail?

journalctl -u <service> -n 50
Enter fullscreen mode Exit fullscreen mode

What is using disk space?

df -h
du -sh *
Enter fullscreen mode Exit fullscreen mode

Where am I and what's here?

pwd
ls -la
Enter fullscreen mode Exit fullscreen mode

Who owns this file and what permissions does it have?

ls -l
Enter fullscreen mode Exit fullscreen mode

Why can't I run this script?

ls -l script.sh
chmod +x script.sh
Enter fullscreen mode Exit fullscreen mode

Where is this file?

find / -name "filename"
Enter fullscreen mode Exit fullscreen mode

These aren't the only commands worth learning.

They're just a useful starting point because they answer real questions you are likely to ask.


Final thought

Linux started making more sense when I stopped treating commands like flashcards.

The command matters, but the problem behind it matters more.

Instead of trying to remember:

journalctl shows logs

I now think:

My service isn't working. What happened? Check the logs.

Instead of:

chmod changes permissions

I think:

This script says "Permission denied." Does it have execute permission?

Instead of:

du shows disk usage

I think:

The server is running out of space. What's taking it?

The commands eventually become easier to remember because you're connecting them to situations.

And I think that's a much better place to start when learning Linux.

Top comments (0)