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 blocks
df
# Force output in megabytes (M) or gigabytes (G)
df -BM # outputs sizes in megabytes
df -BG # outputs sizes in gigabytesAlternatively, use du (disk usage) to check a specific directory’s size:
# Recursively summarize sizes, human-readable
du -h /path/to/dir
# Show only the total for that directory
du -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 & directoriespwd– print working directorycd– change directorymkdir– create directoryrm– remove files/directoriescp– copy files/directoriesmv– move or rename filestouch– create empty fileln– create (symbolic) linksfind– search for files by name, size, date, etc.
Viewing & Editing Files
cat– concatenate & display file contentless– view file content page by pagehead– show first N linestail– show last N linesgrep– search text via patternsdiff– compare file differencescmp– byte-by-byte file comparisonsort– sort file lineswc– count lines/words/bytessed– stream editor for text transformation
System Information & Process Management
uname -a– kernel & system infowhoami– current usernametop– real-time process & resource viewerps aux– snapshot of processeskill,killall– terminate processesdf– disk filesystem usagedu– directory usage (see above)free -h– memory usageuptime– system uptime & loadhtop– interactive process viewer (if installed)
Networking & Remote Access
ifconfig(orip addr) – network interfacesping– test network connectivitytraceroute– trace packet routessh– secure shell accessscp– secure copy over SSHwget,curl– download files over HTTP/FTPnetstat(orss) – sockets & network statsiptables,ufw– firewall rulesroute(orip route) – view/manipulate routingnslookup,dig– DNS queries
Package Management & Updates
apt,yum,dnf,pacman– install/remove packagessudo– execute a command with superuser privilegessystemctl– manage systemd servicesservice– start/stop SysV servicesjournalctl– view systemd logscron,at– schedule tasksalias– create command shortcutsenv,export– set environment variablesdd– 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/Ubuntu
sudo apt-get install screen
# Start a new session
screen
# Detach (leave running in background)
Ctrl-a d
# List sessions
screen -ls
# Reattach to a session
screen -r <session_name>
# Create a new window inside screen
Ctrl-a c
# Next/previous window
Ctrl-a n Ctrl-a p
# List windows
Ctrl-a "
# Split windows (horizontal)
Ctrl-a S
# Close current window
Ctrl-a k
# Rename window
Ctrl-a A
# Kill all screen sessions
killall 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 eth0
sudo 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:
sudo blkid /dev/sda1Add to
/etc/fstab:UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/external ext4 defaults,uid=pi,gid=pi,nofail 0 0Apply:
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 servers
sudo pacman-mirrors -f 5
# Then update your system
sudo pacman -Syu8. Starting Docker Service
If Docker isn’t already running, use:
# Start Docker daemon
sudo systemctl start docker
# Enable it at boot
sudo systemctl enable docker
# Check status
sudo systemctl status docker9. Working with External Hard Drives
9.1. Connect, Partition & Format
Detect drives
sudo lsblkPartition (if needed)
sudo fdisk /dev/sda # Inside fdisk: ‘n’ new, ‘d’ delete, ‘w’ writeFormat partition
# ext4 for Linux sudo mkfs.ext4 /dev/sda1 # exFAT for cross-platform sudo mkfs.exfat /dev/sda1Create mount point & mount
sudo mkdir -p /mnt/external sudo mount /dev/sda1 /mnt/external sudo 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
sudo apt-get install hd-idleConfigure
Edit/etc/default/hd-idle:# Spin down after 180 seconds idle HD_IDLE_OPTS="-i 180 -l /var/log/hd-idle.log"Restart service
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
sudo lsof | grep /home/pi/USBI/O top
sudo apt-get install iotop sudo iotopRunning services
systemctl list-units --type=service --state=runningProcess snapshot
ps aux # or top for live view topSystem logs
dmesg | less journalctl -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