
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:
rootThe root user has unrestricted access to the entire system.
The root user also has its own home directory:
/rootNormal users typically have home directories like:
/home/usernameOn macOS, user home directories are usually located in:
/Users/usernameLinux uses a hierarchical file system structure.
Everything starts from:
/This is called the root directory.
/homeHome directories of normal users.
Example:
/home/johnIf 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
.envTo view hidden files:
ls -apwdShows current directory.
pwdExample output:
/home/johnlsLists contents of current directory.
lscdChanges directory.
cd DocumentsGo to root directory:
cd /Go to home directory:
cdmkdirCreates directories.
mkdir projectstouchCreates files.
touch app.jsrmDeletes files.
rm file.txtrm -rDeletes non-empty directories recursively.
rm -r projectBe careful with this command.
rmdirDeletes empty directories.
rmdir empty-folderclearClears terminal screen.
clearmvMoves or renames files.
Rename example:
mv old.txt new.txtcp -rCopies folders recursively.
cp -r source destinationls -RLists all nested files and directories recursively.
ls -RhistoryDisplays previously executed commands.
historyls -aDisplays hidden files.
ls -als -lLong listing format.
ls -lIncludes:
Show hidden files too:
ls -lacatDisplays file contents.
cat notes.txtuname -aShows system and kernel information.
uname -acat /etc/os-releaseShows Linux distribution details.
cat /etc/os-releaselscpuDisplays CPU information.
lscpulsmemDisplays memory information.
lsmemsudoExecutes command with superuser privileges.
sudo apt updatesu -Switch user.
Become root:
su -|)A pipe sends output of one command as input to another.
Example:
history | lesslessMakes large outputs readable.
Example:
cat huge.log | lessgrepFilters output using pattern matching.
Example:
history | grep dockerThis shows commands containing docker.
>)Redirect output into file.
echo "hello" > file.txtThis overwrites file contents.
>>)Adds text to end of file.
echo "world" >> file.txtUse semicolon (;).
pwd; ls; whoamiAPT stands for:
Advanced Package ToolUsed mainly in:
APT handles:
apt search nginxapt install nginxapt remove nginxapt updateapt upgradeapt autoremoveapt full-upgradeAllows removing/installing packages if needed.
Vim is a powerful terminal-based text editor.
Open file:
vim file.txt:wq:q!ddd10duA$012G/patternnN:%s/old/newLinux 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
developersadduserCreate new user.
sudo adduser johnpasswdChange password.
passwd johngroupaddCreate group.
sudo groupadd developersdeluserDelete user.
sudo deluser johngroupdelDelete group.
sudo groupdel developersusermodModify users.
usermod -g developers johnusermod -G docker,sudo johnusermod -aG docker johngpasswd -dRemove user from group.
gpasswd -d john dockergroupsShow groups of current user.
groupsexitLogout from current user session.
exitchownChange ownership.
chown john file.txtChange owner and group:
chown john:developers file.txtchgrpChange group ownership.
chgrp developers file.txtLinux 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.shchmod g-w file.txtchmod g+x script.shchmod u+x script.shchmod o+x script.shchmod g=rwx file.txtchmod 777Give all permissions to everyone.
chmod 777 file.txtThis 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.