Linux Fundamentals: File System, Commands, Permissions & Package Management

Linux Fundamentals: File System, Commands, Permissions & Package Management

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:

  • Linux File System
  • Linux Folder Structure
  • Essential Linux Commands
  • Pipes & Redirection
  • APT Package Manager
  • Vim Text Editor
  • Users, Groups & Permissions
  • chmod & Ownership

Understanding the Linux File System

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:

  • Regular files
  • Directories
  • Devices
  • Processes
  • Network sockets
  • Hardware components

For example:

  • Your webcam is represented as a file
  • Your keyboard is represented as a file
  • Hard disks are files
  • USB drives are files

This design philosophy makes Linux extremely powerful and flexible.


Root User vs Normal Users

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 Folder Structure Explained

Linux uses a hierarchical file system structure.

Everything starts from:

/

This is called the root directory.


Important Linux Directories

/home

Home directories of normal users.

Example:

/home/john

If a user is created with a home directory, their personal files live here.


/bin

Contains essential executable commands.

Examples:

ls
cp
mv
cat

/sbin

Contains system binaries that usually require superuser privileges.

Examples:

reboot
fdisk
iptables

/lib

Contains shared libraries required by programs inside /bin and /sbin.

Think of these like reusable code modules.


/usr

Historically used for user home directories due to storage limitations in older UNIX systems.

Today it contains:

  • User applications
  • Libraries
  • Documentation
  • System utilities

/usr/local

Programs manually installed by YOU.

Usually used for:

  • Third-party software
  • Custom compiled applications

Accessible to all users.


/opt

Used for third-party applications that keep everything self-contained.

Examples:

  • Google Chrome
  • Discord
  • VS Code

/boot

Contains files required for booting Linux.

Includes:

  • Kernel
  • Bootloader files
  • initramfs

/etc

Contains system-wide configuration files.

Examples:

/etc/passwd
/etc/hosts
/etc/nginx

/dev

Contains device files.

Examples:

  • Mouse
  • Webcam
  • Keyboard
  • Hard drives

Linux interacts with hardware through these files.


/var

Stores variable data.

Examples:

  • Logs
  • Cache
  • Temporary mail data

/var/cache

Stores cached data for applications.


/tmp

Temporary files required by processes.

Files here may be deleted automatically after reboot.


/media

Mount point for removable media.

Examples:

  • USB drives
  • External hard disks

/mnt

Temporary mount points used manually by users/admins.


Hidden Files in Linux

Files beginning with a dot (.) are hidden.

Example:

.bashrc
.gitignore
.env

To view hidden files:

ls -a

Essential Linux Commands


pwd

Shows current directory.

pwd

Example output:

/home/john

ls

Lists contents of current directory.

ls

cd

Changes directory.

cd Documents

Go to root directory:

cd /

Go to home directory:

cd

mkdir

Creates directories.

mkdir projects

touch

Creates files.

touch app.js

rm

Deletes files.

rm file.txt

rm -r

Deletes non-empty directories recursively.

rm -r project

Be careful with this command.


rmdir

Deletes empty directories.

rmdir empty-folder

clear

Clears terminal screen.

clear

mv

Moves or renames files.

Rename example:

mv old.txt new.txt

cp -r

Copies folders recursively.

cp -r source destination

ls -R

Lists all nested files and directories recursively.

ls -R

history

Displays previously executed commands.

history

ls -a

Displays hidden files.

ls -a

ls -l

Long listing format.

ls -l

Includes:

  • Permissions
  • Owner
  • Size
  • Date modified

Show hidden files too:

ls -la

cat

Displays file contents.

cat notes.txt

uname -a

Shows system and kernel information.

uname -a

cat /etc/os-release

Shows Linux distribution details.

cat /etc/os-release

lscpu

Displays CPU information.

lscpu

lsmem

Displays memory information.

lsmem

sudo

Executes command with superuser privileges.

sudo apt update

su -

Switch user.

Become root:

su -

Pipes in Linux (|)

A pipe sends output of one command as input to another.

Example:

history | less

less

Makes large outputs readable.

Example:

cat huge.log | less

grep

Filters output using pattern matching.

Example:

history | grep docker

This shows commands containing docker.


Redirection in Linux

Overwrite File (>)

Redirect output into file.

echo "hello" > file.txt

This overwrites file contents.


Append to File (>>)

Adds text to end of file.

echo "world" >> file.txt

Multiple Commands in One Line

Use semicolon (;).

pwd; ls; whoami

Package Manager: APT

APT stands for:

Advanced Package Tool

Used mainly in:

  • Ubuntu
  • Debian
  • Linux Mint

APT handles:

  • Dependency resolution
  • Package installation
  • Updates
  • Security verification
  • Software repositories

Common APT Commands

Search Package

apt search nginx

Install Package

apt install nginx

Remove Package

apt remove nginx

Update Package Index

apt update

Upgrade Installed Packages

apt upgrade

Remove Unused Dependencies

apt autoremove

Full Upgrade

apt full-upgrade

Allows removing/installing packages if needed.


Vim Text Editor

Vim is a powerful terminal-based text editor.

Open file:

vim file.txt

Important Vim Commands

Save & Quit

:wq

Quit Without Saving

:q!

Delete Current Line

dd

Delete Next 10 Lines

d10d

Undo

u

Move to End of Line & Enter Insert Mode

A

Move to End of Line Without Insert Mode

$

Move to Beginning of Line

0

Jump to Line 12

12G

Search Pattern

/pattern

Next Match

n

Previous Match

N

Replace Text Globally

:%s/old/new

Users, Groups & Permissions

Linux is a multi-user operating system.

There are mainly 3 user types:


1. Root User

Superuser with complete access.


2. Regular User

Normal users with limited permissions.


3. Service User

Used by services/apps.

Examples:

  • Docker
  • Nginx
  • Jenkins
  • Nexus

Best practice:

  • No login shell
  • Limited permissions
  • Better security isolation

Linux Groups

Groups help manage permissions efficiently.

A user can belong to multiple groups.

Example:

docker
sudo
developers

User & Group Commands


adduser

Create new user.

sudo adduser john

passwd

Change password.

passwd john

groupadd

Create group.

sudo groupadd developers

deluser

Delete user.

sudo deluser john

groupdel

Delete group.

sudo groupdel developers

usermod

Modify users.


Change Primary Group

usermod -g developers john

Replace Secondary Groups

usermod -G docker,sudo john

Append Groups

usermod -aG docker john

gpasswd -d

Remove user from group.

gpasswd -d john docker

groups

Show groups of current user.

groups

exit

Logout from current user session.

exit

File Ownership Commands


chown

Change ownership.

chown john file.txt

Change owner and group:

chown john:developers file.txt

chgrp

Change group ownership.

chgrp developers file.txt

Linux Permissions

Linux permissions are divided into 3 categories:

  1. Owner
  2. Group
  3. Others

Each category can have:

| Permission | Meaning | | ---------- | ------------- | | r | Read | | w | Write | | x | Execute | | - | No permission |


Understanding Permission Example

Example:

-rwxr-xr--

Breakdown:

| Section | Meaning | | ------- | ------------------ | | rwx | Owner permissions | | r-x | Group permissions | | r-- | Others permissions |


chmod Command

Used to change permissions.


Remove Execute Permission

chmod -x script.sh

Remove Write Permission for Group

chmod g-w file.txt

Add Execute Permission for Group

chmod g+x script.sh

Add Execute Permission for User

chmod u+x script.sh

Add Execute Permission for Others

chmod o+x script.sh

Set Exact Permissions for Group

chmod g=rwx file.txt

chmod 777

Give 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.


Final Thoughts

Linux fundamentals are the foundation of:

  • DevOps
  • Cloud Engineering
  • Backend Development
  • Cybersecurity
  • System Administration
  • Docker & Kubernetes

Mastering:

  • Linux file system
  • Commands
  • Permissions
  • Users/groups
  • Package management

will make everything else in tech much easier.

The best way to learn Linux is:

  1. Open terminal
  2. Experiment daily
  3. Break things
  4. Fix things
  5. Build projects

That is where real understanding happens.


Practice Challenge

Try these tasks:

  • Create users and groups
  • Change permissions on files
  • Install software using APT
  • Navigate entire filesystem using only terminal
  • Use Vim to edit config files
  • Search logs using grep
  • Redirect outputs into files

The more hands-on you get, the faster Linux starts feeling natural.

Built with ❤️ and lots of coffee by Karan Bhatt.