← Back to Aloygene
Free mini textbook · Beginner

Linux for Beginners

From zero to comfortable in the terminal. Read it one chapter at a time.

1What is Linux?

Linux is an operating system kernel, the core that talks to your hardware. When people say "Linux" they usually mean a full system built around it, called a distribution (distro). Linux is free, open source, and runs most of the world's servers, Android phones, and supercomputers.

Popular distros

DistroGood for
UbuntuBeginners, lots of tutorials
Linux MintWindows-like feel, easy desktop
DebianStable servers
FedoraNewer software
ArchAdvanced users who like to build everything
Tip: If you are new, start with Ubuntu or Linux Mint. There are plenty of tutorials and help online.

2Getting Linux

You do not have to delete Windows. There are safe ways to try it:

wsl --install
Tip: WSL is the easiest option if you are on a Windows PC.

3The Terminal

The terminal (or shell) is where you type commands. The prompt looks like this:

gene@pc:~$

gene is your user, pc is the computer, ~ is your home folder, and $ means you are a normal user (# means root/admin).

Anatomy of a command

command  -options  arguments
ls       -l        /home

Getting help

man ls          # open the manual for ls (press q to quit)
ls --help       # short help
whoami          # who am I?
clear           # clean the screen
Tip: Press Tab to auto-complete names and ↑ to bring back old commands. It saves a lot of typing.

4Files & Folders

Linux has one tree that starts at / (root). No C: or D: drives.

PathMeaning
/Top of everything
/homeUser files (your ~)
/etcConfiguration files
/varLogs and changing data
/tmpTemporary files
/usrInstalled programs

Moving around

pwd             # where am I?
ls              # list files
ls -la          # long list, include hidden files
cd Documents    # go into a folder
cd ..           # go up one level
cd ~            # go home
cd -            # go back to previous folder

Creating, copying, moving, deleting

mkdir project           # make a folder
touch notes.txt         # make an empty file
cp notes.txt backup.txt # copy
cp -r project project2  # copy a folder
mv notes.txt docs/      # move (also used to rename)
rm backup.txt           # delete a file
rm -r project2          # delete a folder
Careful: There is no Recycle Bin for rm. Once a file is deleted, it is gone. Never run rm -rf /, and never run rm -rf without double-checking the path.

Reading files

cat notes.txt       # show whole file
less notes.txt      # scroll through (q to quit)
head -n 5 notes.txt # first 5 lines
tail -n 5 notes.txt # last 5 lines
nano notes.txt      # simple editor (Ctrl+O save, Ctrl+X exit)
Practice: Make a folder called practice, go inside, create three files, copy one, rename another, then delete one. Check each step with ls.

5Users & Permissions

Every file has an owner, a group, and permission bits. See them with ls -l:

-rwxr-xr--  1 gene gene  120 Nov 5 run.sh
 │└┬┘└┬┘└┬┘
 │ │  │  └ others: r--
 │ │  └ group:  r-x
 │ └ owner:  rwx
 └ file type (- file, d folder)

r = read (4), w = write (2), x = execute (1). Add them up per group.

chmod 755 run.sh     # owner rwx, others r-x
chmod +x run.sh      # make it runnable
chown gene file.txt  # change owner
./run.sh             # run it

sudo

sudo runs one command as the administrator (root).

sudo apt update
Careful: If you do not understand a command, do not put sudo in front of it. sudo will not ask twice.

6Installing Software

Linux uses a package manager instead of downloading .exe files. On Ubuntu/Debian/Mint it is apt:

sudo apt update            # refresh the package list
sudo apt upgrade           # update installed software
sudo apt install git       # install
sudo apt remove git        # uninstall
apt search python          # search
Distro familyPackage manager
Ubuntu, Debian, Mintapt
Fedoradnf
Archpacman
Termuxpkg

7Text, Search & Pipes

grep "error" log.txt        # find lines containing "error"
grep -i "gene" notes.txt    # ignore upper/lower case
find . -name "*.html"       # find files by name
wc -l notes.txt             # count lines

Pipes and redirects

The pipe | sends the output of one command into another. > saves output into a file.

ls -la | grep ".txt"        # list, then filter
cat log.txt | wc -l         # count lines
echo "hello" > hello.txt    # write to file (overwrites)
echo "world" >> hello.txt   # append to file
Idea: The power of Linux is small commands that you chain together with pipes.

8Processes

ps aux              # list running processes
top                 # live view (q to quit)
kill 1234           # stop process with ID 1234
kill -9 1234        # force stop
command &           # run in background
Ctrl + C            # stop the current command

Services (systemd)

systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh   # start at boot

9Networking Basics

ping google.com               # is the internet working?
ip a                          # show my IP addresses
curl https://example.com      # fetch a web page
ssh user@server-ip            # log in to another computer
scp file.txt user@server:~/   # copy a file to a server

SSH is how most people control Linux servers from far away.

10Cheat Sheet & Next Steps

Do thisCommand
Where am Ipwd
List filesls -la
Change foldercd
Make folder / filemkdir / touch
Copy / move / deletecp / mv / rm
Read a filecat, less
Search textgrep
Installsudo apt install
Permissionschmod, chown
Processesps, top, kill
Helpman, --help

What to learn next

Final tip: The best way to learn is to practice a little every day, even 15 minutes in the terminal. Do not be afraid of mistakes. Most of them are easy to undo.