1. Displaying Disk Usage in Megabytes and Gigabytes
Linux’s df (disk free) command shows mounted filesystem disk space usage. By default it prints in 1K blocks; with -h it uses human-readable units (KB, MB, GB):
# Show sizes with automatic units (e.g. 1K, 234M, 2G)df -h
# Show sizes in raw 1K blocksdf
# Force output in megabytes (M) or gigabytes (G)df -BM # outputs sizes in megabytesdf -BG # outputs sizes in gigabytesAlternatively, use du (disk usage) to check a specific directory’s size:
# Recursively summarize sizes, human-readabledu -h /path/to/dir
# Show only the total for that directorydu -sh /path/to/dir2. Managing File Permissions with chmod
Unix file permissions control read, write, and execute access. To make a script executable for its owner:
chmod u+x example.sh| Symbol | Meaning |
|---|---|
u | file owner (user) |
g | owning group |
o | others |
+ | add permission |
- | remove permission |
r | read |
w | write |
x | execute |
E.g., chmod ug=rw,o=r file.txt → owner & group read/write; others read only.
3. Top 50 Linux Commands You Should Know
File & Directory Operations
-
ls– list files & directories -
pwd– print working directory -
cd– change directory -
mkdir– create directory -
rm– remove files/directories -
cp– copy files/directories -
mv– move or rename files -
touch– create empty file -
ln– create (symbolic) links -
find– search for files by name, size, date, etc.
Viewing & Editing Files
-
cat– concatenate & display file content -
less– view file content page by page -
head– show first N lines -
tail– show last N lines -
grep– search text via patterns -
diff– compare file differences -
cmp– byte-by-byte file comparison -
sort– sort file lines -
wc– count lines/words/bytes -
sed– stream editor for text transformation
System Information & Process Management
-
uname -a– kernel & system info -
whoami– current username -
top– real-time process & resource viewer -
ps aux– snapshot of processes -
kill,killall– terminate processes -
df– disk filesystem usage -
du– directory usage (see above) -
free -h– memory usage -
uptime– system uptime & load -
htop– interactive process viewer (if installed)
Networking & Remote Access
-
ifconfig(orip addr) – network interfaces -
ping– test network connectivity -
traceroute– trace packet route -
ssh– secure shell access -
scp– secure copy over SSH -
wget,curl– download files over HTTP/FTP -
netstat(orss) – sockets & network stats -
iptables,ufw– firewall rules -
route(orip route) – view/manipulate routing -
nslookup,dig– DNS queries
Package Management & Updates
-
apt,yum,dnf,pacman– install/remove packages -
sudo– execute a command with superuser privileges -
systemctl– manage systemd services -
service– start/stop SysV services -
journalctl– view systemd logs -
cron,at– schedule tasks -
alias– create command shortcuts -
env,export– set environment variables -
dd– low-level data copying (e.g. USB images) -
whereis,which,whatis– locate commands
4. Terminal Multiplexing with Screen
GNU Screen lets you run multiple shells inside one terminal, detach, and resume:
# Install on Debian/Ubuntusudo apt-get install screen
# Start a new sessionscreen
# Detach (leave running in background)Ctrl-a d
# List sessionsscreen -ls
# Reattach to a sessionscreen -r <session_name>
# Create a new window inside screenCtrl-a c
# Next/previous windowCtrl-a n Ctrl-a p
# List windowsCtrl-a "
# Split windows (horizontal)Ctrl-a S
# Close current windowCtrl-a k
# Rename windowCtrl-a A
# Kill all screen sessionskillall screen5. Resolving Default Gateway Conflicts
Having more than one default gateway (e.g. both eth0 and wlan0) causes routing errors. Choose one interface for your internet traffic; remove the other’s gateway:
# Remove the default route via eth0sudo ip route del default via 192.168.1.1 dev eth0Verify with:
ip route show6. Mounting USB Drives Permanently
One-off Mount
# /etc/fstab entry example:/dev/sda1 /home/pi/usb ext4 defaults 0 0# Temporarily mount:sudo mount /dev/sda1 /home/pi/usbBind-Mount (e.g. Nextcloud data folder)
sudo mount --bind /home/pi/usb /portainer/Files/AppData/Config/Nextcloud/Data/pi/files/usbPermanent Mount via UUID
-
Find the UUID:
Terminal window sudo blkid /dev/sda1 -
Add to
/etc/fstab:UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/external ext4 defaults,uid=pi,gid=pi,nofail 0 0 -
Apply:
Terminal window sudo mount -a
Adjust ownership for easy access:
sudo chown -R pi:pi /mnt/external7. Refreshing Arch Linux Mirrors
On Arch Linux, ensure you have the fastest mirrors:
# Update mirror list with the 5 fastest serverssudo pacman-mirrors -f 5
# Then update your systemsudo pacman -Syu8. Starting Docker Service
If Docker isn’t already running, use:
# Start Docker daemonsudo systemctl start docker
# Enable it at bootsudo systemctl enable docker
# Check statussudo systemctl status docker9. Working with External Hard Drives
9.1. Connect, Partition & Format
-
Detect drives
Terminal window sudo lsblk -
Partition (if needed)
Terminal window sudo fdisk /dev/sda# Inside fdisk: ‘n’ new, ‘d’ delete, ‘w’ write -
Format partition
Terminal window # ext4 for Linuxsudo mkfs.ext4 /dev/sda1# exFAT for cross-platformsudo mkfs.exfat /dev/sda1 -
Create mount point & mount
Terminal window sudo mkdir -p /mnt/externalsudo mount /dev/sda1 /mnt/externalsudo chown -R pi:pi /mnt/external
9.2. Permanent Mount
See section 6 above.
10. Configuring HDD Spin-Down with hd-idle
Prolong hardware life and save power by spinning down idle drives:
-
Install
Terminal window sudo apt-get install hd-idle -
Configure
Edit/etc/default/hd-idle:Terminal window # Spin down after 180 seconds idleHD_IDLE_OPTS="-i 180 -l /var/log/hd-idle.log" -
Restart service
Terminal window sudo systemctl restart hd-idle# or for SysV:sudo service hd-idle restart
11. Monitoring Disk Activity & Background Services
-
List open files on a mount
Terminal window sudo lsof | grep /home/pi/USB -
I/O top
Terminal window sudo apt-get install iotopsudo iotop -
Running services
Terminal window systemctl list-units --type=service --state=running -
Process snapshot
Terminal window ps aux# or top for live viewtop -
System logs
Terminal window dmesg | lessjournalctl -xe
12. Optimizing Samba (SMB) Shares
If Samba’s smbd keeps accessing your USB mount, disable kernel change notifications:
- Edit share config in
/etc/samba/smb.conf:
[USB] path = /home/pi/USB browseable = yes read only = no kernel change notify = no- Restart or stop Samba:
sudo systemctl restart smbd# If you no longer need sharing:sudo systemctl stop smbd