Module 2

Introduction to Linux Operating System


What is Linux?


Open Source


Interfaces


Key Features


Linux System Architecture

[ User Applications ]

[ System Libraries ]

[ Linux Kernel ]

[ Hardware ]


Architecture Overview


passwd


who


w

Shows:


tty


lock


stty


script


clear


uname


date


cal


calendar


bc


echo


cd



mkdir


rmdir


cp


rm


mv



cat



Linux File Naming


Hierarchical Directory Structure


Absolute vs Relative Path

Absolute Path


Relative Path


ls


ls -l


ls -d


chmod
Used to change file/directory permissions.
Syntax: chmod [options] mode file
Modes:

Examples:
chmod 644 file1.txt
chmod 755 dir1
chmod u-w file1.txt
chmod go+x dir1


pwd

Shows the current working directory.


cd

Changes directory.
cd /path → go to a specific directory.


cd (home)

cd ~ takes you to your home directory.


cd (parent)

cd .. moves one level up.


ls

Lists files in the current directory.


ls (options)

Common options:
-l → long list
-t → sort by time
-S → sort by size
-h → human-readable sizes
-r → reverse order
Combine: ls -ltr


ls -ltr

Long listing sorted by time, reversed.


Wildcard (*)

* matches any set of characters in filenames.


mkdir

Creates a new directory.


rmdir

Removes an empty directory.


Displaying Files

Tools: cat, less, head, tail.


cat

Shows entire file on screen.
Good for short files.


less

Scrollable file viewer.
Enter → scroll line
Space → scroll page
y → back one line
b → back one page
/text → search
q → quit.


head

Shows top of a file.
Default: first 10 lines.
head -n50 file.txt → first 50 lines.


tail

Same as head, but shows the bottom lines.


cp

Copies a file.


mv

Moves a file to another location.


mv (rename)

Also renames files.


rm

Removes a file.


rm -r

Removes directories and files recursively.
Dangerous—permanent deletion.


File Permissions

Each file has read, write, execute permissions.
ls -l file shows permissions.


Permission Types

r → read
w → write
x → execute (for directories: list contents)


Permission Groups

User → owner
Group → group members
World → everyone else


chmod

Changes permissions (if you own the file).
Format: chmod [u/g/o/a]+[r/w/x] file
Example: give execute to all users.


ps

Shows processes you are running.


top

Shows CPU usage of all processes.


kill

Terminates a process.


I/O Redirection & Piping

a | b → output of a → input of b
a > out.txt → write output to file
a < in.txt → read input from file.


Piping Examples

Combine commands using | to filter or transform output.


wc

Counts lines, words, characters.
Output columns: lines, words, chars.


umask
Sets default permissions for newly created files/directories.
Syntax: umask [mode]
Mode is octal (e.g., 022 prevents write for group/others).

Examples:
umask 022
umask -S
umask -p


chown
Changes owner/group of files.
Syntax: chown owner:group file

Examples:
chown new_owner file1.txt
chown :new_group dir1
chown new_owner:new_group file1.txt
chown -R new_owner:new_group dir1


chgrp
Changes group ownership of files/directories.
Syntax: chgrp new_group file

Examples:
chgrp new_group file1.txt
chgrp new_group dir1
chgrp -R new_group dir1


touch
Creates an empty file or updates timestamps.
Syntax: touch [options] file

Options:

Examples:
touch file1.txt
touch -m file1.txt
touch -r file2.txt file1.txt


more
Displays file content page by page.
Syntax: more [options] file

Options:

Examples:
more file1.txt
more -n file1.txt
more -p 25 file1.txt
more -c file1.txt


find

Searches files/directories based on conditions.
Syntax: find path [options] [expression]

Common:

Examples:
find . -name file1.txt
find . -type d -name dir1
find . -type f -mtime -7
find . -name file1.txt -exec rm {} \;


inode

Every file/dir has an inode storing metadata.

Contains:


Inodes identify files; filenames are just links pointing to inodes.


A hard link points directly to an inode.
Two filenames → same inode, same data.
Created with: ln file1 file2


Notes:

Example:
ln file1.txt file2.txt


A soft link is a separate file storing a path to another file.
Created with: ln -s target linkname


Notes:

Example:
ln -s /path/original.txt link.txt


Creation


File System Relationship


Effect of Deleting Original


Compatibility


Space Usage