1.Introduction to Linux
What is Linux?- Linux is an open-source, Unix-like operating system kernel first released by Linus Torvalds on September 17, 1991. It serves as the foundation for various distributions (distros) that combine the Linux kernel with system software and libraries to create complete operating systems.
- Open Source: Freely available and modifiable.
- Security: Strong permissions system and active community monitoring.
- Stability: Known for robustness and reliability.
- Flexibility: Suitable for desktops, servers, and embedded systems.
2.Basic Linux Commands
Mastering the command line is crucial for effective Linux system administration. Below are some fundamental commands:Command | Description | Example |
pwd | Print current working directory | pwd |
ls | List directory contents | ls -l |
cd | Change directory | cd /home/user |
mkdir | Create a new directory | mkdir new_folder |
rmdir | Remove an empty directory | rmdir old_folder |
rm | Remove files or directories | rm file.txt |
cp | Copy files or directories | cp source.txt destination.txt |
mv | Move or rename files or directories | mv oldname.txt newname.txt |
touch | Create a new empty file | touch newfile.txt |
cat | Concatenate and display file content | cat file.txt |
nano | Open a file in the nano text editor | nano file.txt |
vim | Open a file in the vim text editor | vim file.txt |
3.File System Management
Understanding the Linux file system hierarchy and permissions is essential. File System Hierarchy:- /: Root directory.
- /bin: Essential user binaries.
- /etc: Configuration files.
- /home: User home directories.
- /var: Variable data files.
- /tmp: Temporary files.
- Read (r): View file contents.
- Write (w): Modify file contents.
- Execute (x): Run the file as a program.
- Use chmod to change permissions:
- Symbolic mode: chmod u+x file.sh (Adds execute permission for the user).
- Numeric mode: chmod 755 file.sh (Sets permissions to rwxr-xr-x).
- Use chown to change file owner:
- chown user:group file.txt (Changes owner to ‘user’ and group to ‘group’).
4.User and Group Management
Managing users and groups is vital for system security and resource allocation. User Management Commands:- adduser [username]: Add a new user.
- passwd [username]: Set or change a user’s password.
- deluser [username]: Remove a user.
- addgroup [groupname]: Add a new group.
- delgroup [groupname]: Remove a group.
- usermod -aG [groupname] [username]: Add a user to a group.
5.Process Management
Monitoring and controlling processes ensures system stability and performance. Viewing Processes:- ps aux: Display all running processes.
- top: Interactive view of active processes and system resource usage.
- kill [PID]: Terminate a process by its Process ID.
- killall [process_name]: Terminate all processes with the specified name.
- nice -n [value] [command]: Start a process with a specified priority.
- renice [value] -p [PID]: Change the priority of an existing process.
6.Package Management
Installing, updating, and removing software packages is a common administrative task. Debian-based Systems (e.g., Ubuntu):- apt-get update: Update package lists.
- apt-get upgrade: Upgrade all packages.
- apt-get install [package_name]: Install a new package.
- apt-get remove [package_name]: Remove a package.
- yum update: Update all packages.
- yum install [package_name]: Install a new package.
- yum remove [package_name]: Remove a package.
7.Networking Basics
Configuring and troubleshooting network settings is essential for connectivity. Viewing Network Configuration:- ifconfig: Display network interfaces and configurations.
- ip addr: Show IP addresses assigned to all interfaces.
- ping [hostname/IP]: Test connectivity to a host.
- traceroute [hostname/IP]: Display the route packets take to a host.
- systemctl restart networking: Restart networking services.
- netstat -tuln: List all listening ports and associated services.
8.Shell Scripting Basics
Automating tasks with shell scripts enhances efficiency. Creating a Script:- Create a new file with a .sh extension, e.g., script.sh.
- Add the shebang line: #!/bin/bash.
- Write your commands below the shebang line.
- Make the script executable: chmod +x script.sh.
- Run the script: ./script.sh.
#!/bin/bash
echo "Hello, World!"
9.System Monitoring and Performance
Regular monitoring helps in maintaining optimal system performance. Disk Usage:- df -h: Display disk space usage in a human-readable format.
- du -sh [directory]: Show the size of a specific directory.
- free -h: