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
| Command | What it does |
pwd | Print the directory you are in. |
ls -lah | List files with sizes, permissions and hidden files. |
cd ~/Downloads | Change directory. cd .. goes up one; cd - returns to the previous one. |
tree -L 2 | Directory structure, two levels deep (install tree). |
find . -name "*.iso" | Search by name from the current directory down. |
find /var/log -size +100M | Find files larger than 100 MB. |
which firefox | Where a command actually lives. |
Files and folders
| Command | What it does |
cp -r folder backup/ | Copy a folder recursively. -i asks before overwriting. |
mv old.txt new.txt | Rename or move. |
rm -i file | Delete with a prompt. rm -rf folder deletes without one — there is no recycle bin. |
mkdir -p a/b/c | Create nested directories. |
ln -s /path/to/target link | Create a symbolic link. |
du -sh * | Size of each item in this folder, sorted by eye. |
du -sh * | sort -h | tail -10 | The ten largest items here. |
df -h | Free space on each mounted filesystem. |
Reading files
| Command | What it does |
less file.txt | Page through a file. /word searches, q quits. |
head -20 file / tail -20 file | First or last twenty lines. |
tail -f ~/.local/share/xorg/Xorg.0.log | Follow a log as it grows. Ctrl+C stops it. |
grep -rn "error" ~/.config | Search recursively, with line numbers. |
grep -i error file.log | head | Case-insensitive search, first matches only. |
wc -l file | Count lines. |
diff -u a.txt b.txt | Show what changed between two files. |
Permissions and users
| Command | What it does |
chmod +x script.sh | Make a file executable. |
chmod 644 file | Owner reads and writes; everyone else reads. |
chown user:group file | Change ownership. Needs sudo for files you do not own. |
sudo usermod -aG vboxusers $USER | Add yourself to a group. Log out and back in to apply. |
groups | Which groups you are in. |
passwd | Change your password. |
Processes and services
| Command | What it does |
ps aux | grep firefox | Find a running process. |
top / htop | Live process list. htop is friendlier and needs installing. |
kill 1234 | Ask process 1234 to stop. kill -9 1234 forces it. |
pkill firefox | Kill by name. |
systemctl status sddm | State of a service. |
sudo systemctl restart sddm | Restart the login manager (logs you out). |
systemctl --user restart plasma-plasmashell | Restart the desktop shell without logging out. |
journalctl -b -p err | Errors from this boot. |
journalctl -u NetworkManager -n 50 | Last 50 lines from one service. |
Installing and updating software
| Command | What it does |
sudo apt update | Refresh the package lists. Always run this first. |
sudo apt upgrade | Install available updates. |
sudo apt install htop | Install a package. |
sudo apt remove htop / purge htop | Remove, and remove including configuration. |
apt search video editor | Search the repositories. |
apt list --installed | Everything installed. |
sudo apt autoremove | Remove packages nothing needs any more. |
sudo dpkg -i app.deb | Install a downloaded .deb file. |
sudo apt --fix-broken install | Repair a half-finished installation. |
Disks and USB sticks
| Command | What it does |
lsblk -o NAME,SIZE,MODEL,MOUNTPOINT | Every block device with its size and mount point. The first command to run before anything destructive. |
sudo blkid | UUIDs and filesystem types. |
udisksctl mount -b /dev/sdb1 | Mount a stick as your user, no sudo needed. |
sudo umount /dev/sdb1 | Unmount before removing the stick. |
sudo dd if=image.iso of=/dev/sdb bs=4M status=progress oflag=sync | Write an ISO to a stick. Check of= twice. |
Network
| Command | What it does |
ip a | Interfaces and addresses. |
ip r | Routing table — where traffic actually goes. |
ping -c 4 1.1.1.1 | Is there a working connection at all? |
nmcli device wifi list | Nearby Wi-Fi networks. |
nmcli device wifi connect "SSID" password "pass" | Connect from the terminal. |
ss -tulpn | Open ports and which process owns them. |
curl -I https://example.com | HTTP headers only — a quick reachability test. |
dig example.com | DNS 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
| Command | What it does |
hostnamectl | OS, kernel, architecture in one line each. |
uname -a | Kernel version — needed for header packages. |
lscpu / free -h | CPU details, and RAM in human units. |
lspci | grep -i vga | Which graphics card you have. |
lsusb | USB devices. |
inxi -Fxz | A full system summary, useful when asking for help. |
uptime | How 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
| Syntax | Meaning |
cmd1 | cmd2 | Feed the output of one command into the next. |
cmd > file | Write output to a file, replacing it. |
cmd >> file | Append to a file. |
cmd 2> errors.txt | Send only the errors to a file. |
cmd1 && cmd2 | Run the second only if the first succeeded. |
cmd1 || cmd2 | Run 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.