From zero to comfortable in the terminal. Read it one chapter at a time.
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.
| Distro | Good for |
|---|---|
| Ubuntu | Beginners, lots of tutorials |
| Linux Mint | Windows-like feel, easy desktop |
| Debian | Stable servers |
| Fedora | Newer software |
| Arch | Advanced users who like to build everything |
You do not have to delete Windows. There are safe ways to try it:
wsl --install
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).
command -options arguments
ls -l /home
man ls # open the manual for ls (press q to quit)
ls --help # short help
whoami # who am I?
clear # clean the screen
Tab to auto-complete names and ↑ to bring back old commands. It saves a lot of typing.Linux has one tree that starts at / (root). No C: or D: drives.
| Path | Meaning |
|---|---|
/ | Top of everything |
/home | User files (your ~) |
/etc | Configuration files |
/var | Logs and changing data |
/tmp | Temporary files |
/usr | Installed programs |
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
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
rm. Once a file is deleted, it is gone. Never run rm -rf /, and never run rm -rf without double-checking the path.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, go inside, create three files, copy one, rename another, then delete one. Check each step with ls.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 runs one command as the administrator (root).
sudo apt update
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 family | Package manager |
|---|---|
| Ubuntu, Debian, Mint | apt |
| Fedora | dnf |
| Arch | pacman |
| Termux | pkg |
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
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
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
systemctl status ssh
sudo systemctl start ssh
sudo systemctl enable ssh # start at boot
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.
| Do this | Command |
|---|---|
| Where am I | pwd |
| List files | ls -la |
| Change folder | cd |
| Make folder / file | mkdir / touch |
| Copy / move / delete | cp / mv / rm |
| Read a file | cat, less |
| Search text | grep |
| Install | sudo apt install |
| Permissions | chmod, chown |
| Processes | ps, top, kill |
| Help | man, --help |