
Linux powers servers, cloud infrastructure, Android phones, supercomputers, and most of the internet.
If you're learning DevOps, backend engineering, cybersecurity, or system administration, Linux is non-negotiable.
This guide covers:
One of the most important concepts in Linux is:
Everything in Linux is a file
Unlike Windows or macOS, Linux treats almost everything as files:
For example:
This design philosophy makes Linux extremely powerful and flexible.
Linux has a special superuser called:
root
The root user has unrestricted access to the entire system.
The root user also has its own home directory:
/root
Normal users typically have home directories like:
/home/username
On macOS, user home directories are usually located in:
/Users/username
Linux uses a hierarchical file system structure.
Everything starts from:
/
This is called the root directory.
/homeHome directories of normal users.
Example:
/home/john
If a user is created with a home directory, their personal files live here.
/binContains essential executable commands.
Examples:
ls
cp
mv
cat
/sbinContains system binaries that usually require superuser privileges.
Examples:
reboot
fdisk
iptables
/libContains shared libraries required by programs inside /bin and /sbin.
Think of these like reusable code modules.
/usrHistorically used for user home directories due to storage limitations in older UNIX systems.
Today it contains:
/usr/localPrograms manually installed by YOU.
Usually used for:
Accessible to all users.
/optUsed for third-party applications that keep everything self-contained.
Examples:
/bootContains files required for booting Linux.
Includes:
/etcContains system-wide configuration files.
Examples:
/etc/passwd
/etc/hosts
/etc/nginx
/devContains device files.
Examples:
Linux interacts with hardware through these files.
/varStores variable data.
Examples:
/var/cacheStores cached data for applications.
/tmpTemporary files required by processes.
Files here may be deleted automatically after reboot.
/mediaMount point for removable media.
Examples:
/mntTemporary mount points used manually by users/admins.
Files beginning with a dot (.) are hidden.
Example:
.bashrc
.gitignore
.env
To view hidden files:
ls -a
pwdShows current directory.
pwd
Example output:
/home/john
lsLists contents of current directory.
ls
cdChanges directory.
cd Documents
Go to root directory:
cd /
Go to home directory:
cd
mkdirCreates directories.
mkdir projects
touchCreates files.
touch app.js
rmDeletes files.
rm file.txt
rm -rDeletes non-empty directories recursively.
rm -r project
Be careful with this command.
rmdirDeletes empty directories.
rmdir empty-folder
clearClears terminal screen.
clear
mvMoves or renames files.
Rename example:
mv old.txt new.txt
cp -rCopies folders recursively.
cp -r source destination
ls -RLists all nested files and directories recursively.
ls -R
historyDisplays previously executed commands.
history
ls -aDisplays hidden files.
ls -a
ls -lLong listing format.
ls -l
Includes:
Show hidden files too:
ls -la
catDisplays file contents.
cat notes.txt
uname -aShows system and kernel information.
uname -a
cat /etc/os-releaseShows Linux distribution details.
cat /etc/os-release
lscpuDisplays CPU information.
lscpu
lsmemDisplays memory information.
lsmem
sudoExecutes command with superuser privileges.
sudo apt update
su -Switch user.
Become root:
su -
|)A pipe sends output of one command as input to another.
Example:
history | less
lessMakes large outputs readable.
Example:
cat huge.log | less
grepFilters output using pattern matching.
Example:
history | grep docker
This shows commands containing docker.
>)Redirect output into file.
echo "hello" > file.txt
This overwrites file contents.
>>)Adds text to end of file.
echo "world" >> file.txt
Use semicolon (;).
pwd; ls; whoami
APT stands for:
Advanced Package Tool
Used mainly in:
APT handles:
apt search nginx
apt install nginx
apt remove nginx
apt update
apt upgrade
apt autoremove
apt full-upgrade
Allows removing/installing packages if needed.
Vim is a powerful terminal-based text editor.
Open file:
vim file.txt
:wq
:q!
dd
d10d
u
A
$
0
12G
/pattern
n
N
:%s/old/new
Linux is a multi-user operating system.
There are mainly 3 user types:
Superuser with complete access.
Normal users with limited permissions.
Used by services/apps.
Examples:
Best practice:
Groups help manage permissions efficiently.
A user can belong to multiple groups.
Example:
docker
sudo
developers
adduserCreate new user.
sudo adduser john
passwdChange password.
passwd john
groupaddCreate group.
sudo groupadd developers
deluserDelete user.
sudo deluser john
groupdelDelete group.
sudo groupdel developers
usermodModify users.
usermod -g developers john
usermod -G docker,sudo john
usermod -aG docker john
gpasswd -dRemove user from group.
gpasswd -d john docker
groupsShow groups of current user.
groups
exitLogout from current user session.
exit
chownChange ownership.
chown john file.txt
Change owner and group:
chown john:developers file.txt
chgrpChange group ownership.
chgrp developers file.txt
Linux permissions are divided into 3 categories:
Each category can have:
| Permission | Meaning | | ---------- | ------------- | | r | Read | | w | Write | | x | Execute | | - | No permission |
Example:
-rwxr-xr--
Breakdown:
| Section | Meaning | | ------- | ------------------ | | rwx | Owner permissions | | r-x | Group permissions | | r-- | Others permissions |
Used to change permissions.
chmod -x script.sh
chmod g-w file.txt
chmod g+x script.sh
chmod u+x script.sh
chmod o+x script.sh
chmod g=rwx file.txt
chmod 777Give all permissions to everyone.
chmod 777 file.txt
This means:
| User Type | Permissions | | --------- | ----------- | | Owner | rwx | | Group | rwx | | Others | rwx |
⚠️ Avoid using 777 unless absolutely necessary because it creates security risks.
Linux fundamentals are the foundation of:
Mastering:
will make everything else in tech much easier.
The best way to learn Linux is:
That is where real understanding happens.
Try these tasks:
The more hands-on you get, the faster Linux starts feeling natural.