linux complete Reference - Notes By ShariqSP
Linux Overview and Commands
What is Linux?
Linux is a free and open-source operating system kernel initially developed by Linus Torvalds in 1991. It is based on the Unix operating system and is widely used in servers, desktops, smartphones, embedded systems, and more.
Why do we need Linux?
- Open Source: Linux is distributed under an open-source license, allowing users to access and modify the source code freely.
- Stability: Linux systems are known for their stability and reliability, making them ideal for critical tasks and server environments.
- Flexibility: Linux can be customized to suit various needs and preferences, thanks to its modular design and extensive customization options.
- Security: Linux has a strong focus on security, with robust access control mechanisms and frequent security updates.
- Cost-effective: Linux is often used as a cost-effective alternative to proprietary operating systems, as it can be installed and used for free.
Linux Architecture and Components
Kernel: The core of the operating system responsible for managing hardware resources and providing system services.
Shell: The command-line interface for interacting with the system.
Filesystem: The hierarchical structure for organizing directories and files.
Utilities: Command-line tools for performing various tasks.
Libraries: System libraries providing essential functions and services.
Graphical Interface: Optional desktop environment for a graphical user interface.
Package Management: Systems for installing, updating, and removing software packages.
Common Linux Commands
ls
List directories
Example: ls -l
pwd
Print working directory
Example: pwd
cd
Navigate through directories
Example: cd /path/to/directory
mkdir
Create directories
Example: mkdir new_directory
mv
Move or rename files
Example: mv file1 file2
cp
Copy files
Example: cp file1 file2
rm
Delete files or directories
Example: rm file1
touch
Create blank/empty files
Example: touch file.txt
ln
Create symbolic links
Example: ln -s /path/to/target link_name
cat
Display file contents
Example: cat file.txt
clear
Clear the terminal display
Example: clear
echo
Print text
Example: echo "Hello, world!"
less
Display paged outputs
Example: less file.txt
man
Access manual pages
Example: man ls
uname
Get basic information about the OS
Example: uname -a
whoami
Get the active username
Example: whoami
tar
Extract and compress files
Example: tar -xvf file.tar
grep
Search for a string within an output
Example: grep "pattern" file.txt
head
Return the specified number of lines from the top
Example: head -n 10 file.txt
tail
Return the specified number of lines from the bottom
Example: tail -n 10 file.txt
diff
Find the difference between two files
Example: diff file1 file2
cmp
Check if two files are identical
Example: cmp file1 file2
comm
Combine the functionality of diff and cmp
Example: comm file1 file2
sort
Sort the content of a file
Example: sort file.txt
export
Export environment variables
Example: export VARIABLE=value
zip
Zip files
Example: zip archive.zip file1 file2
unzip
Unzip files
Example: unzip archive.zip
ssh
Secure Shell command
Example: ssh user@hostname
service
Start and stop services
Example: service apache2 start
ps
Display active processes
Example: ps aux
kill and killall
Kill active processes by process ID or name
Example: kill PID
Example: killall process_name
df
Display disk filesystem information
Example: df -h
mount
Mount file systems
Example: mount /dev/sdb1 /mnt
chmod
Change file permissions
Example: chmod 755 file.sh
chown
Grant ownership of files or folders
Example: chown user:group file.txt
ifconfig
Display network interfaces and IP addresses
Example: ifconfig
traceroute
Trace all the network hops to reach the destination
Example: traceroute google.com
wget
Direct download files from the internet
Example: wget http://example.com/file.txt
ufw
Firewall command
Example: ufw allow 22/tcp
iptables
Base firewall for all other firewall utilities to interface with
Example: iptables -A INPUT -p tcp --dport 80 -j ACCEPT
apt, pacman, yum, rpm
Package managers depending on the distro
Example: apt-get install package_name
Example: pacman -S package_name
Example: yum install package_name
Example: rpm -i package.rpm
sudo
Escalate privileges in Linux
Example: sudo apt-get update
cal
View a command-line calendar
Example: cal
alias
Create custom shortcuts for regularly used commands
Example: alias ll='ls -l'
dd
Create bootable USB sticks
Example: dd if=image.iso of=/dev/sdX bs=4M
whereis
Locate the binary, source, and manual pages for a command
Example: whereis ls
whatis
Find what a command is used for
Example: whatis ls
top
View active processes live with their system usage
Example: top
useradd and usermod
Add new user or change existing user's data
Example: useradd username
Example: usermod -aG groupname username
passwd
Create or update passwords for existing users
Example: passwd username