Basic Linux Commands for Beginners (With Examples)
You've connected to your server over SSH for the first time and you're staring at an empty terminal. From navigating files to installing packages, from permissions to process management, we explain the most-used Linux commands with examples.
When you rent a VPS, you'll most likely manage the server from the command line rather than a graphical interface. It may look intimidating at first, but most everyday tasks can be handled with twenty or thirty commands. In this guide we cover the commands you'll use most on Ubuntu 24.04, when to use them and what to watch out for. If you don't know how to connect to your server yet, first take a look at our What is SSH article.
Tip: The best way to learn commands is to try them. A freshly installed test server with no important data is ideal for this. If something breaks, you can reinstall the server and start over.
A first look at the command line
When you connect, you'll see a line similar to this:
root@sunucu:~#
Here root is the username, sunucu is the machine's name, ~ is the folder you're in (your home directory) and # shows that you're logged in as an administrator. For regular users this symbol is $.
If you forget how a command is used, you have two helpers:
ls --help
man ls
You exit a man page with the q key. In addition, the Tab key autocompletes file and command names, and the up arrow brings back previous commands. These two greatly reduce typos.
Navigating files and folders
pwd # şu an hangi klasördesiniz
ls # klasördeki dosyaları listeler
ls -lah # gizli dosyalar dahil, boyutlar okunaklı biçimde
cd /var/www # belirtilen klasöre geçer
cd .. # bir üst klasöre çıkar
cd ~ # ev dizinine döner
cd - # bir önceki klasöre döner
(pwd shows the folder you're in, ls lists files, ls -lah includes hidden files with human-readable sizes, cd changes folders: .. goes up one level, ~ returns home, - returns to the previous folder.)
In Linux, file paths start with / and are case-sensitive: Site.txt and site.txt are two different files. Files whose names start with a dot (like .env and .bashrc) are hidden and only appear with ls -a.
Folders you'll come across often:
| Folder | What's inside? |
|---|---|
/etc |
System and service configuration files |
/var/log |
Log files |
/var/www |
Where websites usually live |
/home |
Home directories of regular users |
/root |
The root user's home directory |
/tmp |
Temporary files (may be deleted on reboot) |
Creating, copying, moving and deleting files
mkdir yedekler # klasör oluşturur
mkdir -p proje/static/css # iç içe klasörleri tek seferde oluşturur
touch notlar.txt # boş dosya oluşturur
cp ayar.conf ayar.conf.yedek # dosyayı kopyalar
cp -r site/ site-yedek/ # klasörü içindekilerle kopyalar
mv eski.txt yeni.txt # yeniden adlandırır
mv dosya.zip /tmp/ # başka bir klasöre taşır
rm notlar.txt # dosyayı siler
rm -r eski-klasor/ # klasörü içindekilerle siler
(mkdir creates a folder, -p creates nested folders in one go; touch creates an empty file; cp copies, -r copies a folder with its contents; mv renames or moves; rm deletes, -r deletes a folder with its contents.)
Warning: There's no recycle bin in Linux. A file deleted with
rmdoesn't come back. Double-check the path, especially when typingrm -rf, and back up a configuration file withcpbefore changing it.
Viewing and editing file contents
cat dosya.txt # tüm içeriği ekrana basar
less /var/log/syslog # uzun dosyaları sayfa sayfa gösterir (q ile çıkış)
head -n 20 dosya.txt # ilk 20 satır
tail -n 50 dosya.txt # son 50 satır
tail -f /var/log/nginx/access.log # dosyaya eklenen satırları canlı izler
(cat prints the whole file, less pages through long files (quit with q), head/tail show the first/last lines, and tail -f follows new lines live.)
The easiest editor for beginners is nano:
nano /etc/hosts
After making changes, save with Ctrl+O and Enter, and exit with Ctrl+X. Learning vim later is also useful, but nano is enough for day one.
Searching: find and grep
find /var/www -name "*.php" # adı .php ile biten dosyaları bulur
find /var/log -size +100M # 100 MB'tan büyük dosyaları bulur
grep "error" /var/log/nginx/error.log # dosyada "error" geçen satırları gösterir
grep -ri "veritabani" /etc/myapp/ # klasörde büyük-küçük harf duyarsız arar
(find locates files by name or size; grep shows lines containing a word, and -ri searches a folder recursively, case-insensitively.)
You can chain commands together with a pipe (|). The output of one command becomes the input of the next:
ps aux | grep nginx
cat access.log | grep "404" | wc -l
The second example counts how many 404 errors there are in the access log.
Users, sudo and file permissions
Rather than doing everything as root, it's safer to create a privileged user for yourself:
adduser ahmet
usermod -aG sudo ahmet
This user prefixes commands that require administrator rights with sudo: sudo apt update.
Strings like -rwxr-xr-- in the output of ls -l show file permissions. The groups of three apply to the owner, the group and others, in that order; r means read, w write and x execute.
chmod 644 index.html # sahibi okur/yazar, diğerleri yalnızca okur
chmod 755 betik.sh # sahibi her şeyi yapar, diğerleri okur ve çalıştırır
chmod +x betik.sh # dosyayı çalıştırılabilir yapar
chown www-data:www-data -R /var/www/site # sahipliği web sunucusu kullanıcısına verir
(644: the owner reads/writes, others only read; 755: the owner can do everything, others read and execute; +x makes a file executable; chown hands ownership to the web server user.)
It may be tempting to use chmod 777 to fix a problem, but that makes the file writable by everyone and creates a security hole. The right fix is usually to correct the ownership (chown).
Package management (apt)
On Ubuntu and Debian, software is installed with apt:
sudo apt update # paket listelerini yeniler
sudo apt upgrade -y # kurulu paketleri günceller
sudo apt install nginx # paket kurar
sudo apt remove nginx # paketi kaldırır
apt search htop # depoda paket arar
(update refreshes package lists, upgrade updates installed packages, install/remove add or remove a package, search looks for a package in the repositories.)
Always run apt update before installing; otherwise you may get a "not found" error because of an outdated package list.
Services and processes
Programs running in the background, such as the web server or database, are managed with systemctl:
systemctl status nginx # servis çalışıyor mu?
sudo systemctl restart nginx
sudo systemctl enable nginx # açılışta otomatik başlasın
(status shows whether the service is running, restart restarts it, enable makes it start automatically at boot.)
To see running processes and stop them if necessary:
ps aux | grep python
kill 12345 # PID'i 12345 olan süreci kibarca durdurur
kill -9 12345 # yanıt vermiyorsa zorla durdurur
(kill politely stops the process with PID 12345; kill -9 forces it if it doesn't respond.)
We cover topics like monitoring resource usage, reading logs and the firewall in detail in our useful server management commands article.
System information
uname -a # çekirdek sürümü
lsb_release -a # dağıtım sürümü (ör. Ubuntu 24.04 LTS)
uptime # sunucu ne zamandır açık, yük ortalaması
free -h # RAM kullanımı
df -h # disk kullanımı
ip a # ağ arayüzleri ve IP adresleri
(Kernel version, distribution version, uptime and load average, RAM usage, disk usage, and network interfaces with IP addresses.)
Archiving and compression: tar and zip
To back up a folder or move it to another server, it helps to bundle it into a single file first. The most common format on Linux is .tar.gz:
tar -czf site-yedek.tar.gz /var/www/site # klasörü sıkıştırarak arşivler
tar -tzf site-yedek.tar.gz # arşivin içeriğini listeler
tar -xzf site-yedek.tar.gz -C /tmp/ # arşivi /tmp klasörüne açar
What the letters mean: c create, x extract, t list, z compress with gzip, f file name. If you'll be sharing files with Windows users, zip is more convenient:
sudo apt install -y zip unzip
zip -r site.zip /var/www/site
unzip site.zip -d /tmp/site
Network and download commands
To check whether the server can reach the internet, whether a site responds, or to download a file, you use these:
ping -c 4 google.com # bağlantıyı test eder, 4 paket gönderir
curl -I https://ornek.com # sitenin yalnızca HTTP başlıklarını getirir
wget https://ornek.com/dosya.tar.gz # dosyayı bulunduğunuz klasöre indirir
ss -tulpn # hangi portları hangi programlar dinliyor
(ping tests connectivity with 4 packets, curl -I fetches only the HTTP headers, wget downloads a file into the current folder, ss -tulpn shows which programs listen on which ports.)
ss -tulpn is especially important: if a web server isn't working, this is where you see whether the port is actually being listened on, or whether another program has grabbed that port. To find out which IP a domain points to, dig ornek.com +short also helps; we explain this in detail in our What is DNS article.
Small habits that save time
historylists your previous commands with numbers. Type!42to run command number 42 again.- Ctrl+R searches your history: type a few letters and the latest matching command appears.
- Ctrl+C stops the running command, Ctrl+L clears the screen.
- To keep a long-running job going even if your connection drops, use
tmux: start a session withtmux, and if you get disconnected, reconnect and typetmux attach. - You can chain commands with
&&:sudo apt update && sudo apt upgrade -yruns the second command only if the first succeeds.
What's next?
Once you're comfortable with these commands, focus on protecting your server: read our Linux server security guide for SSH keys, the firewall and automatic updates. If you're looking for a server to practice on, TürkiyeVPS VPS plans come with root access. Without installing anything on your computer, you can connect from your browser with the Console button in the customer panel and try these commands right away.
Frequently Asked Questions
Do I need to memorize Linux commands?
No. The ones you use often will stick naturally over time. For the rest, --help, man and Tab completion are enough. Keeping your own notes file also helps.
What's the difference between sudo and root?
root is the system's all-powerful user. sudo, on the other hand, lets a regular user run a single command with administrator rights. That way you don't work with full privileges all the time, which reduces the risk of mistakes.
Can I recover a file I deleted by accident?
Files deleted on the command line don't go to a recycle bin, so they usually can't be recovered. The only reliable solution is regular backups. Make a copy of a file before making important changes.
Do these commands work on every Linux distribution?
File, search, permission and process commands are the same on almost every distribution. The package manager differs: Ubuntu/Debian use apt, while AlmaLinux/Rocky Linux use dnf.
You might also like
The tools you'll reach for first when the server slows down, the disk fills up or a service crashes. We explai...
Moving your website to a new host without your visitors noticing is possible. From making backups to changing...
If your visitors are in Iran, Turkey, the Caucasus or Iraq, where your server is located affects how fast your...