Sangharsh OS

Documentation/System

Terminal commands for daily driving

The commands worth knowing by heart on Sangharsh OS, grouped by what you are trying to do. Open Konsole and keep this page in a browser tab next to it.

You do not need the terminal to use Sangharsh OS. You do need it the moment something goes wrong, because the terminal is the only place that tells you what actually happened.

Three habits. Press Tab to complete file and command names. Press Ctrl+R and type to search your command history. Read a command before you paste it — especially anything with sudo, rm or dd in it.

Getting around

CommandWhat it does
pwdPrint the directory you are in.
ls -lahList files with sizes, permissions and hidden files.
cd ~/DownloadsChange directory. cd .. goes up one; cd - returns to the previous one.
tree -L 2Directory structure, two levels deep (install tree).
find . -name "*.iso"Search by name from the current directory down.
find /var/log -size +100MFind files larger than 100 MB.
which firefoxWhere a command actually lives.

Files and folders

CommandWhat it does
cp -r folder backup/Copy a folder recursively. -i asks before overwriting.
mv old.txt new.txtRename or move.
rm -i fileDelete with a prompt. rm -rf folder deletes without one — there is no recycle bin.
mkdir -p a/b/cCreate nested directories.
ln -s /path/to/target linkCreate a symbolic link.
du -sh *Size of each item in this folder, sorted by eye.
du -sh * | sort -h | tail -10The ten largest items here.
df -hFree space on each mounted filesystem.

Reading files

CommandWhat it does
less file.txtPage through a file. /word searches, q quits.
head -20 file / tail -20 fileFirst or last twenty lines.
tail -f ~/.local/share/xorg/Xorg.0.logFollow a log as it grows. Ctrl+C stops it.
grep -rn "error" ~/.configSearch recursively, with line numbers.
grep -i error file.log | headCase-insensitive search, first matches only.
wc -l fileCount lines.
diff -u a.txt b.txtShow what changed between two files.

Permissions and users

CommandWhat it does
chmod +x script.shMake a file executable.
chmod 644 fileOwner reads and writes; everyone else reads.
chown user:group fileChange ownership. Needs sudo for files you do not own.
sudo usermod -aG vboxusers $USERAdd yourself to a group. Log out and back in to apply.
groupsWhich groups you are in.
passwdChange your password.

Processes and services

CommandWhat it does
ps aux | grep firefoxFind a running process.
top / htopLive process list. htop is friendlier and needs installing.
kill 1234Ask process 1234 to stop. kill -9 1234 forces it.
pkill firefoxKill by name.
systemctl status sddmState of a service.
sudo systemctl restart sddmRestart the login manager (logs you out).
systemctl --user restart plasma-plasmashellRestart the desktop shell without logging out.
journalctl -b -p errErrors from this boot.
journalctl -u NetworkManager -n 50Last 50 lines from one service.

Installing and updating software

CommandWhat it does
sudo apt updateRefresh the package lists. Always run this first.
sudo apt upgradeInstall available updates.
sudo apt install htopInstall a package.
sudo apt remove htop / purge htopRemove, and remove including configuration.
apt search video editorSearch the repositories.
apt list --installedEverything installed.
sudo apt autoremoveRemove packages nothing needs any more.
sudo dpkg -i app.debInstall a downloaded .deb file.
sudo apt --fix-broken installRepair a half-finished installation.

Disks and USB sticks

CommandWhat it does
lsblk -o NAME,SIZE,MODEL,MOUNTPOINTEvery block device with its size and mount point. The first command to run before anything destructive.
sudo blkidUUIDs and filesystem types.
udisksctl mount -b /dev/sdb1Mount a stick as your user, no sudo needed.
sudo umount /dev/sdb1Unmount before removing the stick.
sudo dd if=image.iso of=/dev/sdb bs=4M status=progress oflag=syncWrite an ISO to a stick. Check of= twice.

Network

CommandWhat it does
ip aInterfaces and addresses.
ip rRouting table — where traffic actually goes.
ping -c 4 1.1.1.1Is there a working connection at all?
nmcli device wifi listNearby Wi-Fi networks.
nmcli device wifi connect "SSID" password "pass"Connect from the terminal.
ss -tulpnOpen ports and which process owns them.
curl -I https://example.comHTTP headers only — a quick reachability test.
dig example.comDNS lookup.

Archives

tar -czf backup.tar.gz ~/Documents     # create
tar -xzf backup.tar.gz                 # extract
tar -tzf backup.tar.gz | head          # list contents without extracting
zip -r archive.zip folder/             # zip
unzip archive.zip -d destination/      # unzip

System information

CommandWhat it does
hostnamectlOS, kernel, architecture in one line each.
uname -aKernel version — needed for header packages.
lscpu / free -hCPU details, and RAM in human units.
lspci | grep -i vgaWhich graphics card you have.
lsusbUSB devices.
inxi -FxzA full system summary, useful when asking for help.
uptimeHow long since boot, and load average.

Power

systemctl suspend          # sleep
systemctl reboot
systemctl poweroff
shutdown -h +30            # power off in 30 minutes
shutdown -c                # cancel a scheduled shutdown

Pipes, redirection and chains

SyntaxMeaning
cmd1 | cmd2Feed the output of one command into the next.
cmd > fileWrite output to a file, replacing it.
cmd >> fileAppend to a file.
cmd 2> errors.txtSend only the errors to a file.
cmd1 && cmd2Run the second only if the first succeeded.
cmd1 || cmd2Run the second only if the first failed.
sudo !!Re-run the last command with sudo.

Five one-liners worth stealing

# the ten biggest files under your home directory
find ~ -type f -size +100M -exec du -h {} + 2>/dev/null | sort -h | tail -10

# what is listening on a port and who owns it
sudo ss -tulpn | grep :8080

# a dated tarball of your config, ready for the next mistake
tar -czf ~/config-$(date +%F).tar.gz ~/.config

# watch a value every two seconds
watch -n 2 'df -h /'

# search every file in a folder for a word, skipping binaries
grep -rI --exclude-dir={node_modules,.git} "TODO" .

When you are stuck

man ls opens the manual; ls --help gives the short version; tldr ls (install tldr) gives three examples and no theory. And the log is almost always right: journalctl -b -p err after a failure tells you what broke.