Parts of the command line
The linux command line is not one singular thing, it consists of many parts. Each having a specific important purpose. Each of these parts is modular and can be swapped out to fit your needs.
The Terminal:
The terminal (often called terminal emulator), is a front end interface that allows you to interact with the shell of the system.
At its core its just a window in which you input text which gets passed down to the shell and then displays the output of the shell.
The terminal emulator does not understand commands, it just passes input to the shell and renders output.
Common terminal emulators include: Konsole, Kitty, Gnome Terminal, and Ghostty.
The Shell:
The shell is a program that interprets commands and then runs the right programs.
It is like the bridge between the user and the kernel. its the most basic form of interacting with your system.
The most commonly used shell programs are: Bash, Zsh, Powershell.
The Binaries:
The shell itself doesnt execute anything, it just interprets a command and then executes the correct binary programs with the correct arguments.
Each command is just calling one or more of those binary programs.
So the commands like: cd, ls, cat.
Are basically just names of executable binaries.
All major Linux distro’s come with a standard set of these commands (binaries).
Most of these binaries are part one of the following projects: gnu-coreutils, util-linux, procps-ng, iproute2, iputils. and then there are a number of binaries that are their own projects.
But you can be sure that all major Linux distros come with the binaries of those 5 projects, so if you learn those you are set.
Commonly used commands
π Files & Directories
| Command | Project | Description | Example | 
|---|---|---|---|
| ls | gnu | List files and directories | ls /home | 
| cd | bash | Change the current directory | cd /home | 
| pwd | gnu | Print current working directory | pwd | 
| cp | gnu | Copy files or directories | cp file.txt copy.txt | 
| mv | gnu | Move or rename files/directories | mv file.txt moved.txt | 
| rm | gnu | Remove files or directories | rm file.txt | 
| mkdir | gnu | Create directories | mkdir folder | 
| rmdir | gnu | Remove empty directories | rmdir folder | 
| touch | gnu | Create empty file or update timestamp | touch file.txt | 
| cat | gnu | Display or concatenate file contents | cat file.txt | 
| echo | bash | Print text to stdout | echo "hello world" | 
| basename | gnu | Strip directory path from filename | basename /path/file.txt | 
| dirname | gnu | Strip filename to show directory path | dirname /path/file.txt | 
π Privileges & Ownership
| Command | Project | Description | Example | 
|---|---|---|---|
| chmod | gnu | Change file permissions | chmod +x script.sh | 
| chown | gnu | Change file owner and group | chown user:group file.txt | 
| sudo | other | Execute command as root user | sudo rm file.txt | 
| su | util-linux | Switch to root user | su | 
π Search & Filters
| Command | Project | Description | Example | 
|---|---|---|---|
| find | gnu | Search for files in directories | find /home -name "*.txt" | 
| grep | gnu | Search text in files using patterns | grep "error" log.txt | 
| sed | gnu | Filters text using given rules | sed 's/old/new/' file.txt | 
| xargs | gnu | Use output as arguments | cat dirs.txt | xargs rmdir | 
βοΈ Processes
| Command | Project | Description | Example | 
|---|---|---|---|
| ps | procps-ng | Show currently running processes | ps aux | 
| kill | gnu | Terminate a process by PID | kill 1234 | 
| pkill | gnu | Terminate a process by name | pkill firefox | 
π¦ Archiving & Compression
| Command | Project | Description | Example | 
|---|---|---|---|
| tar | gnu | Archive or extract files | tar -cvf archive.tar file.txt | 
| gzip | gnu | Compress files | gzip archive.tar | 
| gunzip | gnu | Decompress gzip files | gunzip archive.tar.gz | 
π Networking
| Command | Project | Description | Example | 
|---|---|---|---|
| ping | iputils | Test network connectivity | ping google.com | 
| ip | iproute2 | Show or configure network interfaces | ip addr | 
| curl | other | Downloads files from the web | curl -O http://example.com/file | 
| wget | other | Downloads files from the web | wget http://example.com/file | 
πΎ Storage & Disks
| Command | Project | Description | Example | 
|---|---|---|---|
| mount | util-linux | Mount disks or drive | mount /dev/sda1 /mnt/usb | 
| umount | util-linux | Unmount disks or drive | umount /mnt/usb | 
| fdisk | util-linux | Manages disks or drives | fdisk -l | 
π₯οΈ System & Other
| Command | Project | Description | Example | 
|---|---|---|---|
| shutdown | util-linux | Shut down the system | shutdown | 
| reboot | util-linux | Reboot the system | reboot | 
| clear | gnu | Clears the terminal output | clear | 
| env | gnu | Configure environment variables | env | 
| export | gnu | Configure temp environment variables | export VAR=value | 
| which | other | Locate a command in PATH | which cat | 
| whereis | util-linux | Locate binaries | whereis cat | 
| type | bash | Show command type information | type cat | 
| uname | gnu | Show system and kernel information | uname -a | 
| uptime | procps-ng | Show system uptime and load | uptime | 
| who | util-linux | Show who is logged in | who | 
| whoami | gnu | Show current user | whoami | 
| id | gnu | Show user and group IDs | id | 
| groups | gnu | List groups for a user | groups | 
Shebangs
You will often encounter shell scripts starting with #!/bin/bash, the #! is called a shebang. It is used to specify which interpreter will be used to run the script.
So if your script uses bash specific scripting syntax, then you put a bash shebang on the first line of your script.
If you want your script to be posix compatible so it can run on other unix like systems that don’t have bash, then you use the sh shebang.
The sh shell is compatible with alot more unix like operating systems than just linux, making your scripts more portable at the cost of bash specific scripting features.
Bash Compatible
| Shebang | Comment | Debian | Arch | Fedora | MacOS | FreeBSD | 
|---|---|---|---|---|---|---|
| #!/bin/bash | the classic bash location on linux | β | β | β | β | β | 
| #!/usr/bin/bash | the modern bash location on linux | β | β | β | β | β | 
| #!/bin/env bash | the env binary is almost never in bin/ | β | β | β | β | β | 
| #!/usr/bin/env bash | finds bash via the path | β | β | β | β | β | 
Posix Compatible
| Shebang | Comment | Debian | Arch | Fedora | MacOS | FreeBSD | 
|---|---|---|---|---|---|---|
| #!/bin/sh | the default sh location on most systems | β | β | β | β | β | 
| #!/usr/bin/sh | the sh binary is almost never in usr/bin/ | β | β | β | β | β | 
| #!/bin/env sh | the env binary is almost never in bin/ | β | β | β | β | β | 
| #!/usr/bin/env sh | finds sh via the path | β | β | β | β | β | 
Conclusion
Just use #!/bin/bash or #!/usr/bin/bash for linux bash scripts.
Just use #!/usr/bin/env bash for cross platform bash scripts.
Just use #!/bin/sh or #!/usr/bin/env sh for cross platform posix scripts.
File globbing
In many tools including many shells you can filter your file or directory selection with something called Globbing, and its a way of quickly filtering your file or directory selection selection. If you want to select a specific set of files or directories from the command line you can use this following specific syntax that is specifically designed for that purpose.
Basics
. | Current directory | 
.. | Parent directory | 
~ | Home directory | 
* | Matches any file or directory | 
** | Matches any file or directory recursively | 
/ | Directory separator | 
Examples
ls * # list files and dirs in the current directory
ls ** # list files and dirs recursively starting from this dir
ls *.txt # list text files in this dir
ls **/*.txt # list text files recursively starting from this dir
ls . # list files and dirs inside the current directory
ls .. # list files and dirs inside the parent directory
ls ~ # list files and dirs inside the home directory
ls / # list files and dirs inside the root directory
ls text* # list files and dirs starting with "text" in the name
ls *text # list files and dirs ending with "text" in the name
ls *text* # list files and dirs containing "text" anywhere in the name
ls file.c* # list files with extensions starting with "c" (c, cpp, cs)
ls file?.txt # list txt files named "file" + any character (file1.txt, file2.txt)
ls file??.txt # list txt files named "file" + any 2 characters (file12.txt, file13.txt)
ls file{1,2,3}.txt # list files: file1.txt, file2.txt, and file3.txt
ls {foo,bar,hello}.txt # list files: foo.txt, bar.txt, and hello.txt
ls file[123].txt # list files: file1.txt, file2.txt, and file3.txt
ls file[a-f].txt # list files with a single char in the range a-c (fileb.txt, filec.txt)
lsΒ file[!0-9].txt # list files where the character after "file" is NOT a digit (0-9)
Piping
comming soon…
Chaining
comming soon…
Loops
comming soon…