Linux Fundamental

From Zero to Terminal Hero

Agenda

  1. Struktur Direktori
  2. File Management
  3. Navigasi
  4. Membaca File
  5. Text Processing
  6. System Monitoring
  7. ...
  1. Process Management
  2. Compression
  3. Networking
  4. Permission
  5. SSH
  6. Package Manager
  7. Terminal Editor

1. Struktur Direktori

FHS - Filesystem Hierarchy

Direktori Fungsi
/ Root - titik awal semua direktori
/bin Command dasar sistem (ls, cp, mv)
/sbin System binaries (fdisk, reboot)
/usr/bin User command (banyak installed apps)
/usr/sbin System admin commands
/usr/local/bin User-installed software
/etc Konfigurasi sistem
/home Direktori user
/var Log, cache, mail
/tmp File sementara
/dev Device files

Konsep Penting

Di Linux, everything is a file — hardware direpresentasikan sebagai file di /dev

/
├── bin/     ← Command dasar
├── etc/     ← Konfigurasi
├── home/    ← Data user
├── var/     ← Log & cache
└── dev/     ← Devices

2. File Management

mkdir — Buat Direktori

Membuat folder baru

mkdir myfolder
mkdir -p parent/child

-p = buat parent jika belum ada

touch — Buat File Kosong

Membuat file atau update timestamp

touch file.txt
touch -t 202401011200 file

cp — Menyalin File

Menyalin file atau direktori

cp file.txt backup.txt
cp -r folder/ backup/

-r = recursive untuk folder

mv — Pindahkan / Rename

Memindahkan atau rename file

mv old.txt new.txt
mv file.txt /home/user/

rm — Hapus File

Menghapus file atau folder

rm file.txt
rm -r folder/
rm -rf folder/

⚠️ rm -rf / = hapus seluruh sistem! Linux tidak ada Recycle Bin.

3. Navigasi

pwd — Print Working Directory

Menampilkan lokasi direktori sekarang

pwd
# Output: /home/alice/projects

cd — Change Directory

Berpindah ke direktori lain

cd /etc        # Absolute path
cd ..          # Parent directory
cd ~           # Home directory
cd -           # Direktori sebelumnya

ls — List Isi Direktori

Menampilkan isi direktori

ls
ls -l
ls -a
ls -lh
ls -lt

ls — Opsi Lengkap

Opsi Arti
-l Format detail
-a Tampilkan hidden files
-lh Size dalam KB/MB/GB
-lt Sort by modification time

find — Mencari File

Mencari file berdasarkan nama, ukuran, tanggal

find / -name "config.txt"
find . -name "*.log"
find . -mtime -7
find . -size +100M

4. Membaca File

cat — Concatenate

Menampilkan seluruh isi file

cat file.txt
cat file1.txt file2.txt

Cocok untuk file kecil

head — Baris Awal

Menampilkan 10 baris pertama

head file.txt
head -n 5 file.txt

Berguna untuk cek header file

tail — Baris Akhir

Menampilkan 10 baris terakhir

tail file.txt
tail -f /var/log/syslog

-f = follow mode untuk monitoring log real-time

less — Pager Interaktif

Menampilkan file dengan scroll

less file.txt

Navigasi: Arrow, PageUp/Down, / search, q quit

Cocok untuk file besar

wc — Word Count

Statistik file (baris, kata, byte)

wc file.txt             # baris kata byte
wc -l file.txt          # Hanya jumlah baris
wc -w file.txt          # Hanya jumlah kata
wc -c file.txt          # Hanya jumlah byte

5. Text Processing

grep — Pattern Matching

Mencari text dalam file

grep "error" file.log
grep -i "error" file.log    # Case insensitive
grep -r "pattern" folder/   # Recursive
grep -n "word" file.txt     # Dengan nomor baris
ps aux | grep nginx         # Cari di proses

sed — Stream Editor

Edit text secara stream

sed 's/old/new/' file.txt        # Replace pertama
sed 's/old/new/g' file.txt       # Replace semua
sed -i 's/old/new/g' file.txt    # Edit in-place
sed '1,5d' file.txt              # Hapus baris 1-5

awk — Text Processing

Memproses text berbasis kolom

awk '{print $1}' file.txt           # Print kolom 1
awk -F: '{print $1}' /etc/passwd    # Delimiter :
awk '$3 > 100' file.txt             # Filter angka

Pipes & Redirects

Menghubungkan output antar command

echo "text" > file.txt      # Write (overwrite)
echo "text" >> file.txt     # Append
cat < file.txt              # Input dari file
cat file | grep error       # Pipe output
cmd > /dev/null 2>&1        # Suppress all output

6. System Monitoring

top — Task Manager

Menampilkan proses secara real-time

top
Kolom Arti
PID Process ID
USER Pemilik proses
%CPU Penggunaan CPU
%MEM Penggunaan RAM
COMMAND Nama program

Shortcuts: k=kill, q=quit, M=sort RAM, P=sort CPU

df — Disk Free

Menampilkan penggunaan disk

df -h

du — Disk Usage

Menampilkan size folder

du -sh /var/log
du -h --max-depth=1 .

free — Memory Usage

Menampilkan penggunaan RAM

free -h

available lebih penting dari free — Linux cache agresif

uname & uptime — System Info

Informasi sistem

uname -a        # Semua info
uname -r        # Kernel version
uptime          # Waktu aktif sistem
whoami          # User sekarang
id              # User & group ID

7. Process Management

ps — Process Status

Melihat list proses

ps              # Proses sendiri
ps aux          # Semua proses
ps aux | grep nginx

kill — Menghapus Proses

Menghentikan proses

kill 1234              # Graceful (SIGTERM)
kill -9 1234           # Force kill (SIGKILL)
kill -15 1234          # Graceful (explicit)
pkill nginx            # Kill by name
killall nginx          # Kill semua instance
Signal Arti
-15 (TERM) Graceful — proses cleanup dulu
-9 (KILL) Paksa — langsung terminate
-1 (HUP) Reload config

nice & renice — Priority

Mengatur prioritas proses

nice -n 10 ./script.sh    # Jalankan dengan priority rendah
renice 5 -p 1234          # Ubah priority proses berjalan

Priority: -20 (tertinggi) sampai +20 (terendah)

Background & Foreground

Menjalankan proses di background

./script.sh &            # Jalankan di background
Ctrl+Z                   # Pause & masukkan background
bg                       # Lanjutkan di background
fg                       # Bawa ke foreground
jobs                     # List background jobs

8. Compression

tar — Tape Archive

Membuat/extracting archive

tar -cvf archive.tar folder/     # Create
tar -xvf archive.tar             # Extract
tar -cvzf archive.tar.gz folder/ # Compress gzip
tar -xvzf archive.tar.gz         # Extract gzip
tar -tvf archive.tar             # List isi

zip & unzip

Kompresi format zip

zip -r backup.zip folder/
unzip backup.zip

gzip — GNU Zip

Kompresi single file

gzip file.txt          # → file.txt.gz
gunzip file.txt.gz     # → file.txt

9. Networking

ping — Test Konektivitas

Menguji koneksi ke host

ping google.com
ping -c 4 8.8.8.8      # 4 kali lalu stop

curl — HTTP Client

Mengambil data dari server

curl https://api.example.com
curl -I https://google.com    # Headers saja
curl -o file.zip URL          # Download file
curl -X POST -d "k=v" URL     # POST request

wget — Download

Mendownload file dari web

wget https://example.com/file.tar.gz
wget -c URL    # Resume download

Network Tools

Command Fungsi
ip addr Konfigurasi network
netstat -tuln Port yang terbuka
ss -tuln Alternatif modern netstat
nslookup DNS lookup
traceroute Trace routing path

10. Permission

Permission Model

3-level permission: Owner | Group | Others

-rwxr-xr-- 1 alice dev file.txt
 |||||||||
 ||||||||└── Others (r--)
 ||||||└──── Group (r-x)
 ||||└────── Owner (rwx)
 |└───────── Type (-=file, d=dir)
Simbol Nilai Arti
r 4 Read (baca)
w 2 Write (tulis)
x 1 Execute (jalankan)

chmod — Change Mode

Mengubah permission file

chmod 755 script.sh    # rwxr-xr-x
chmod 644 file.txt     # rw-r--r--
chmod 777 folder/      # Full access (WASPADA!)

# Symbolic mode
chmod u+x file         # Tambah execute owner
chmod go-w file        # Hapus write group/others
chmod a+r file         # Read untuk semua
Target Arti
u User (owner)
g Group
o Others
a All

chown — Change Owner

Mengubah owner dan group

chown bob file.txt
chown bob:dev file.txt
chown -R bob:dev folder/
chgrp dev file.txt

Special Permissions

SetUID, SetGID, Sticky Bit

chmod u+s program    # SetUID - jalankan sebagai owner
chmod g+s folder/    # SetGID - inherit group
chmod +t /tmp        # Sticky bit - hanya owner bisa hapus

11. SSH

SSH — Secure Shell

Akses remote terminal dengan enkripsi

Client (laptop) ←── Encrypted (port 22) ──→ Server

SSH Connect

Menghubungkan ke server remote

ssh user@192.168.1.100
ssh -p 2222 user@server.com   # Port custom

SSH Key Generation

Membuat key pair untuk autentikasi

ssh-keygen -t ed25519 -C "email@example.com"
# Output:
# ~/.ssh/id_ed25519      (private - JANGAN SEBAR)
# ~/.ssh/id_ed25519.pub  (public - copy ke server)

SSH Key Copy

Menyalin public key ke server

ssh-copy-id user@server.com
# Sekarang login tanpa password!

scp — Secure Copy

Transfer file via SSH

scp file.txt user@server:/path/      # Upload
scp user@server:/path/file.txt .     # Download
scp -r folder/ user@server:/path/   # Folder

rsync — Remote Sync

Sinkronisasi folder

rsync -avz folder/ user@server:/backup/
rsync -avz --delete folder/ user@server:/backup/

-a=archive, -v=verbose, -z=compress

12. Package Manager

APT — Debian/Ubuntu

Advanced Package Tool

apt update                # Update repo list
apt upgrade               # Upgrade semua paket
apt install nginx         # Install paket
apt remove nginx          # Uninstall paket
apt search nginx          # Cari paket
apt list --installed      # List installed
apt autoremove            # Hapus unused deps

YUM/DNF — RHEL/CentOS/Fedora

Yellowdog Updater Modified / Dandified YUM

yum update                # Update semua
yum install nginx         # Install
yum remove nginx          # Remove
yum search nginx          # Search
yum list installed        # List installed
dnf update                # DNF (newer)

Pacman — Arch Linux

Package Manager

pacman -Syu               # Sync & upgrade
pacman -S nginx           # Install
pacman -R nginx           # Remove
pacman -Ss nginx          # Search
pacman -Q                 # List installed

Snap & Flatpak — Universal

Cross-distro package managers

# Snap
snap install nginx
snap remove nginx
snap list

# Flatpak
flatpak install flathub org.nginx.Nginx
flatpak run org.nginx.Nginx

Package Manager Comparison

Distro Manager Command
Debian/Ubuntu APT apt install
RHEL/CentOS/Fedora DNF dnf install
Arch Linux Pacman pacman -S
openSUSE Zypper zypper install
Universal Snap snap install
Universal Flatpak flatpak install

13. Environment Variables

Environment Variables

Variabel yang menyimpan konfigurasi sistem

echo $PATH              # Lihat PATH
echo $HOME              # Lihat home directory
echo $USER              # Lihat username
env                     # Lihat semua env var
printenv                # Sama dengan env

Set & Export Variables

Mengatur variabel lingkungan

export VAR=value        # Set untuk session ini
VAR=value command       # Set untuk satu command
echo 'export VAR=value' >> ~/.bashrc  # Permanent

PATH — Command Search

Direktori yang dicari untuk command

echo $PATH
# /usr/local/bin:/usr/bin:/bin

# Tambah direktori ke PATH
export PATH=$PATH:/new/directory

14. Shell Config Files

~/.bashrc & ~/.zshrc

Konfigurasi shell untuk user

# ~/.bashrc (bash)
# ~/.zshrc (zsh)

# Contoh konfigurasi
alias ll='ls -lh'
alias gs='git status'
export EDITOR=vim
export PATH=$PATH:/usr/local/bin

Apply Changes

Memuat ulang konfigurasi

source ~/.bashrc        # Reload bash
source ~/.zshrc         # Reload zsh
. ~/.bashrc            # Shortcut

~/.bash_profile vs ~/.bashrc

File Ketika
~/.bash_profile Login shell (SSH, terminal baru)
~/.bashrc Interactive non-login shell

Untuk consistency, source .bashrc dari .bash_profile

15. Sudo & Su

sudo — Super User Do

Menjalankan command sebagai root/superuser

sudo apt update
sudo nano /etc/hosts
sudo -i                   # Interactive root shell
sudo -u bob command       # Sebagai user lain
sudo -k                   # Reset timestamp

sudoers — Configure sudo

Mengatur siapa boleh sudo

sudo visudo              # Edit sudoers file

# Contoh: alice boleh sudo tanpa password
alice ALL=(ALL) NOPASSWD: ALL

su — Switch User

Berpindah ke user lain

su -                    # Switch ke root
su - alice              # Switch ke alice
su -c "command" root    # Jalankan command sebagai root

Perbedaan sudo vs su

Command Use Case
sudo Sekali-sekali, lebih aman
su Sering jadi user lain
sudo -i Interactive root session

Best Practice: Gunakan sudo daripada su untuk keamanan

16. Terminal Editor

nano — Editor Pemula

Editor sederhana dengan shortcut di bawah

nano file.txt
Shortcut Fungsi
Ctrl+O Save
Ctrl+X Exit
Ctrl+W Search
Ctrl+K Cut line
Ctrl+U Paste
Ctrl+G Help

vim — Editor Powerful

3 mode: Normal | Insert | Command

Normal (default) ←→ Insert (i/a/o) ←→ Command (:)

vim — Normal Mode

Navigasi dan editing

Key Aksi
h j k l Kiri / bawah / atas / kanan
gg Ke awal file
G Ke akhir file
dd Hapus baris
yy Copy baris
p Paste
u Undo
x Hapus karakter

vim — Command Mode

Save, quit, search

:w          " Save
:q          " Quit
:wq / :x    " Save & quit
:q!         " Quit tanpa save
:set nu     " Tampilkan nomor baris
/search     " Cari teks
n           " Next match

vim — Insert Mode

Mengetik text

Key Aksi
i Insert sebelum cursor
a Insert setelah cursor
o Baris baru di bawah
O Baris baru di atas
Esc Kembali ke Normal mode

Quick Reference

Command Summary

Kategori Command
Navigasi cd, pwd, ls, find
File mkdir, cp, mv, rm, touch
Baca cat, head, tail, less, wc -l
Text grep, sed, awk
Monitor top, df, du, free
Process ps, kill, kill -9
Compress tar, zip, gzip
Network ping, curl, wget, ssh
Package apt, dnf, pacman
Permission chmod, chown
Env echo $VAR, export
Config ~/.bashrc, ~/.zshrc
Admin sudo, su

Terima Kasih

Praktikkan setiap hari!

echo "Linux is fun!"