LINUX
Linux is an open-source operating system based on Linux kernel, first released in 1991 by
Linux Torvalds.
Key Characteristics:
Open-source: freely available, allowing for modification and distribution.
Kernel-based: Relies on the Linux kernel for core functionality, managing hardware and
resources.
Unix-like: Designed to be compatible with UNIX operating systems
Highly customizable: Available in numerous distributions with varying features and user
interfaces.
Wide range of uses: from servers and supercomputers to smartphones and embedded
systems, Linux powers a vast array of devices
Components of a Linux System:
Kernel: The core of the OS, managing hardware and resources
System User Space: includes the shell, daemons, and desktop environment
Applications: Software for various tasks, including office suites, web browsers, and
development tools.
Popular Linux Distributions:
Ubuntu: A user-friendly distro known for its ease of use and large community.
Debian: A stable and versatile distro with a strong focus on community involvement.
Linux File System: is hierarchical, meaning it has a root directory from which all the other files
and directories branch out, forming a tree-like structure. The Filesystem Hierarchy Standard
(FHS) defines the directory structure and directory contents in Linux systems. The root
directory (/) serves as a starting point:
/bin: Essential command binaries, like ls, cp, and mv.
/boot: Bootloader files, including the kernel
/dev: Device files representing hardware components.
/etc: Configuration files for the system.
/home: User home directories.
/lib: Essential shared libraries.
/mnt: Temporary mount points for filesystems.
/opt: Optional software packages.
/proc: Virtual filesystem providing process and kernel information.
/root: Home directory for the root user.
/sbin: System binaries, typically for administrative tasks.
/tmp: Temporary files.
/usr: Secondary hierarchy for user programs and data.
/var: Variable data files like logs, databases, and email.
Key Filesystem Types in Linux
Ext4: The most widely used filesystem in Linux, known for its balance of performance,
reliability, and features.
XFS: High-performance filesystem with robust scalability, often used in enterprise
environments.
Btrfs: A newer filesystem designed for fault tolerance, repair, and easy administration.
ZFS: Known for data integrity and scalability, commonly used in storage solutions.
vfat: Compatibility layer for FAT filesystems, often used in USB drives and external
devices.
NFS: Network File System, used to share files over a network.
Inodes are fundamental to the Linux filesystem, serving as data structures that store metadata
about files. Each file and directory is associated with an inode, which contains information such
as:
File size
File permissions
Ownership (user and group)
Timestamps (last access, modification, and change)
File type
Number of hard links
The inode number is unique within a filesystem and is used to identify the file. The inode does
not store the file name itself; instead, the directory entry maps the file name to its inode.
File Permissions and Ownership: Each fie has three sets of permissions for the owner, the
group, and others:
Read(r): Permission to read the contents of the file (4)
Write(w): Permission to modify the file (2)
Execute(x): Permission to execute the file as a program (1)
PuTTY: is a free and open-source terminal emulator, primarily used for connecting to remote
servers via protocols like SSH, Telnet, and more. It's a popular tool for system administrators,
network engineers, and developers who need to manage and control remote systems from a
Windows machine.
PuTTY emulates a terminal, enabling users to connect to remote servers and execute commands
as if they were physically connected to that server.
PuTTY supports various protocols, including:
SSH: Secure Shell, the most common protocol for secure remote access.
Telnet: A less secure protocol for remote access, often used for legacy systems.
rlogin: Another older protocol for remote access.
Serial: For direct connections to devices via serial ports.
Key Features of PuTTY:
Secure connections: PuTTY offers strong encryption through SSH, ensuring secure data
transmission when connecting to remote servers.
File transfer: PuTTY provides command-line tools like pscp and psftp for secure file
transfers to and from remote servers.
Customizable: It allows users to configure various settings like host, port, protocol, and
SSH keys.
Cross-platform: While primarily known for Windows, PuTTY has been ported to other
operating systems like Linux and macOS.
PuTTY is also used for tasks like:
Server administration: Managing servers, configuring network settings, and
troubleshooting issues.
Software development: Testing and debugging applications on remote servers.
Network monitoring: Monitoring network devices and services.
Step 1: Basic Commands
Topic Example Commands
Navigation pwd, cd, ls, tree
File Handling touch, mkdir, rm, cp, mv, find
Viewing File Content cat, less, more, head, tail, nano, vim
File Permissions chmod, chown, umask, ls -l
Wildcards & Globbing *, ?, []
pwd : shows the current directory you’re in
cd : change directory
cd /etc
cd ~ # Go to home
cd .. # Go one level up
cd - # Go to the previous directory
ls : list directory contents
ls -l # Long format (permissions, owners, size)
ls -a # Show hidden files (starting with .)
ls -lh # Human-readable file sizes
ls -lt # Sort by modified time
ls -R # Recursive listing (list all files and folders, including the contents of all
subdirectories, recursively)
mkdir : make directories
mkdir mydir
mkdir -p folder1/folder2/folder3 # -p : creates parent directories if they don’t
exist
rmdir : remove directory, only works when directory is empty
rmdir emptyfolder
rm : remove directory, deletes folders + all its content
rm file.txt
rm -i file.txt # Asks before deleting
rm -r nonemptyfolder
rm -rf folder/ # Force delete everything inside
rm -rf / # removes entire system – NEVER run this
touch : create empty files, in scripts, log files or quickly test file behavior.
touch file.txt
cp : copy files and directories
cp file.txt backup.txt # source_file destination file
cp source_file destination_directory
cp -r myfolder /tmp/ # source_directory destination_directory
cp file1 file2 file3 destination_directory
cp -i file.txt /etc/ # Prompts before overwrite
-n or –no-cloober : prevents overwriting existing files
-p or --preserve : preserves file attributes(permissions, timestamps, ownership)
-f or --force : if the destination file cannot be opened for writing, it will be deleted
first and then copied.
-a or –archive : it preserves most attributes and copies recursively
mv : move or rename files
mv file1.txt file2.txt # Rename old_filename to new_filename
mv file1.txt /home/isha/ # Move source_file to destination_directory
mv *.txt /tmp/ # Move all .txt files
mv source_directory destination_directory
Like cp, mv also overwrites without confirmation unless you use -i.
find : search for files and directories
find [path] [options] [expression]
path : where to start searching
options : refine ur search
expressions : criteria like filenames or sizes
Option What It Does Example
-name Searches files by name (case- find ~ -name "notes.txt"
"pattern" sensitive).
-iname
"pattern"
Case-insensitive name search. find ~ -iname "notes.*"
Finds only files (f) or directories find /var/log -type f
-type f/d
(d).
-size +10M Finds files larger than 10MB. find / -size +100M
Finds files modified in the last 7 find ~ -mtime -7
-mtime -7
days.
Finds files with specific find ~ -perm 644
-perm 644
permissions.
Runs commands on found files find . -name "*.tmp" -exec rm
-exec
(e.g., delete). {} \;
-empty Finds empty files/directories. find ~ -empty
find . -type f -name “*.log” -exec rm {} \; # find and delete .log files
find . -type f -exec chmod 644 {} \; # set permissions on all files
cat : used to display the contents of files, concatenate files, and create new files.
cat filename # display file content
cat > newfile.txt # create a new file
cat > greetings.txt
Hello Isha!
Welcome to Linux.
<Ctrl + D>
cat >> existing.txt # adds new content at the end of the existing.txt use Ctrl + D to
stop.
cat file1.txt file2.txt > combined.txt # merges file1.txt and file2.txt into
combined.txt
cat -n file.txt # Adds line numbers to the output
cat -A file.txt # useful to visualize tabs (^I), line ends ($), etc.
less : view large files or outputs without flooding your terminal
less filename # opens the file in a read-only pager (u cant edit it, but u can scroll
and search)
more : view the contenty of text files, page-by-page, especially when the content doesn’t
fit on one screen.
more +20 myfile.txt # start from line 20
head : view top of the file
head file.txt # first 10 lines
head -n 20 file.txt # first 20 lines
tail : view bottom of the file
tail file.txt # last 10 lines
tail -n 50 file.txt # last 50 lines
tail -f logfile.log # follow a file in real-time
chmod : change file/directory permissions
chmod u+x script.sh # Add execute permission to user
chmod g-w file.txt # Remove write from group
chmod o=r file.txt # Set read-only for others
chmod a+x myapp # Make executable for everyone
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 700 secret.sh # rwx------ (only owner can read/write/execute)
chmod 777 mydir # full access for everyone (⚠️risky!)
chown : change the owner
chown isha file.txt # file.txt is now owned by user isha
chown isha:developers file.txt # owner is isha, group is developers
chown :developers file.txt # change only group
chown -R isha:devteam /project/ # changes all files/folders under /project/
chgrp : change only the group
chgrp developers file.txt #change the group
chgrp -R devs /data/ #recursive group changes
umask : defines default permission bits that are masked (removed) when new files or
directories are created.
Final permissions = Default permissions – umask
1. Wildcards : a powerful feature in Linux that lets you match multiple files or patterns
without typing full names.
Symbol Meaning Example
* Matches zero or more characters *.txt matches file.txt, data1.txt, abc.txt
? Matches exactly one character file?.txt matches file1.txt, file2.txt
Matches any one character inside the file[1-3].txt matches file1.txt, file2.txt,
[]
brackets file3.txt
{} Matches comma-separated patterns file{1,2}.txt matches file1.txt, file2.txt
grep(global regular expression print) : used for searching and matching text patterns in
files contained in the regular expressions.
grep “error” /var/log/syslog # search for “error” in a log file
grep -i “error” /var/log/syslog # same but case-insensitive
grep -r “TODO” # search recursively in all files in a folder
grep -n “main” script.sh # show line numbers with matches
grep -v “DEBUG” logs.txt # invert match (lines that do NOT contain pattern)
-l # show filenames only
--color=auto # highlight matches
# Difference between start and enable
Command Description
systemctl stop <service> Stops it immediately
Command Description
systemctl disable <svc> Disables auto-start at boot
systemctl restart <svc> Restarts it (stop → start)
systemctl status <svc> Shows current status and logs