Linux complete notes
Linux complete notes
Linux is an open-source, Unix-like operating system kernel that serves as the core component of
many different operating systems. It was created by Linus Torvalds in 1991 and has since become
one of the most widely used operating system kernels in the world. Linux is known for its stability,
security, and versatility and is commonly used in a variety of computing environments, including
servers, desktop computers, mobile devices, and embedded systems.
It's important to note that when people refer to "Linux," they often mean a complete operating
system that includes the Linux kernel along with various software components and tools. These
complete operating systems, built on top of the Linux kernel, are often referred to as "Linux
distributions" or "Linux distros." Examples of popular Linux distributions include Ubuntu, Debian,
Red Hat Enterprise Linux, CentOS, Fedora, and many others.
1. Open Source: Linux is distributed under open-source licenses (such as the GNU General
Public License), which means that its source code is freely available for anyone to view,
modify, and distribute. This openness has led to a vibrant and collaborative development
community.
2. Multiuser and Multitasking: Linux supports multiple users and can run multiple processes
concurrently. This makes it suitable for use in both single-user desktop environments and
multiuser server environments.
3. Stability: Linux is known for its stability and reliability. It can run for extended periods
without needing to be rebooted, making it a preferred choice for server applications.
4. Security: Linux benefits from a robust security model. Regular security updates and the
ability to customize security settings make it a popular choice for security-conscious users
and organizations.
5. Portability: The Linux kernel can run on a wide range of hardware architectures, from
small embedded systems to powerful servers. This versatility has contributed to its
widespread adoption.
6. Package Management: Most Linux distributions come with package management
systems that simplify software installation, updates, and removal. Popular package
managers include APT (used in Debian-based systems), YUM (used in Red Hat-based
systems), and Pacman (used in Arch Linux).
Advantages of Linux:
1. Open Source: Linux is open-source software, which means that its source code is freely
available to the public. This encourages collaboration, transparency, and customization by
developers and users.
2. Cost-Effective: Most Linux distributions are free to use, which can significantly reduce
software licensing costs for individuals and organizations.
3. Security: Linux is known for its robust security features. The open-source nature of the
system allows for rapid identification and patching of security vulnerabilities.
4. Stability: Linux is renowned for its stability and uptime. It's often used in critical
infrastructure and server environments where reliability is paramount.
5. Customization: Linux is highly customizable. Users can choose from various desktop
environments, window managers, and software packages to create a personalized
computing environment.
6. Community Support: There is a vast and active Linux community that provides support,
documentation, and forums to help users troubleshoot issues and learn about the
system.
7. Software Repository: Most Linux distributions offer a vast repository of software
packages that can be easily installed and updated using package managers like APT or
YUM.
8. Compatibility: Linux supports a wide range of hardware architectures, making it versatile
for different types of devices, from servers to embedded systems.
9. Resource Efficiency: Linux is known for its ability to run on older hardware or resource-
constrained devices, making it suitable for reviving older computers.
10. Command Line Interface (CLI): Linux offers a powerful command-line interface, which is
favored by system administrators and power users for its efficiency and flexibility.
Disadvantages of Linux:
1. Limited Software Support: Some proprietary software and applications are not available
for Linux, which can be a limitation for users who rely on specific programs.
2. Learning Curve: Linux can have a steeper learning curve, especially for users accustomed
to other operating systems like Windows or macOS.
3. Hardware Drivers: While Linux supports many hardware devices, some less common or
specialized hardware may lack official Linux drivers, requiring manual configuration or
workarounds.
4. Gaming: Although Linux gaming has improved, it still lags behind Windows in terms of
game compatibility and performance.
5. Fragmentation: The Linux ecosystem is fragmented due to the many different
distributions, each with its own package management system and configuration. This can
lead to compatibility issues between distributions.
6. Lack of Technical Support: While community support is strong, commercial support
options for Linux may not be as readily available or robust as those for other operating
systems.
7. Document Compatibility: Some document formats may not be fully compatible with
Linux-based office suites, leading to formatting issues when sharing documents with
users of other operating systems.
8. Software Dependencies: Installing software from outside the official repositories can
sometimes result in dependency conflicts or issues that need to be resolved manually.
9. Limited Commercial Software: Some industries heavily rely on specialized commercial
software that may not have Linux versions or equivalents.
10. Perceived Complexity: The perception of Linux as a complex operating system can
discourage some users from trying it, even though user-friendly distributions have made
significant strides in usability.
Linux Distributions List
There are on an average six hundred Linux distributors providing different features. Here, we'll
discuss about some of the popular Linux distros today.
1) Ubuntu It came into existence in 2004 by Canonical and quickly became popular. Canonical wants
Ubuntu to be used as easy graphical Linux desktop without the use of command line. It is the most
well known Linux distribution. Ubuntu is a next version of Debian and easy to use for newbies. It
comes with a lots of preinstalled apps and easy to use repositories libraries. Earlier, Ubuntu uses
GNOME2 desktop environment but now it has developed its own unity desktop environment. It
releases every six months and currently working to expand to run on tablets and smartphones.
2) Linux Mint Mint is based on Ubuntu and uses its repository software so some packages are
common in both. Earlier it was an alternative of Ubuntu because media codecs and proprietary
software are included in mint but was absent in Ubuntu. But now it has its own popularity and it uses
cinnamon and mate desktop instead of Ubuntu's unity desktop environment.
3) Debian Debian has its existence since 1993 and releases its versions much slowly then Ubuntu and
mint. This makes it one of the most stable Linux distributor. Ubuntu is based on Debian and was
founded to improve the core bits of Debian more quickly and make it more user friendly. Every
release name of Debian is based on the name of the movie Toy Story.
4) Red Hat Enterprise / CentOS Red hat is a commercial Linux distributor. There products are red hat
enterprise Linux (RHEL) and Fedora which are freely available. RHEL is well tested before release and
supported till seven years after the release, whereas, fedora provides faster update and without any
support. Red hat uses trademark law to prevent their software from being redistributed. CentOS is a
community project that uses red hat enterprise Linux code but removes all its trademark and make it
freely available. In other words, it is a free version of RHEL and provide a stable platform for a long
time.
5) Fedora It is a project that mainly focuses on free software and provides latest version of software.
It doesn't make its own desktop environment but used 'upstream' software. By default it has
GNOME3 desktop environment. It is less stable but provides the latest stuff.
1. Process Management:
• Creation and termination of processes (programs in execution).
• Allocation of CPU time to processes, scheduling, and managing process priorities.
• Interprocess communication and synchronization.
2. Memory Management:
• Allocation and deallocation of memory to processes.
• Managing virtual memory, including swapping data between RAM and disk.
• Ensuring protection and isolation of processes' memory spaces.
3. File System Management:
• Creation, deletion, and management of files and directories.
• Control of access permissions to files and directories.
• Managing file attributes and metadata.
• Maintaining file system integrity and consistency.
4. Device Management:
• Managing input and output devices such as keyboards, mice, disks, and network
interfaces.
• Handling device drivers and controlling device access.
• Managing device queues and ensuring efficient device utilization.
5. User Interface:
• Providing a user-friendly interface for interacting with the system, which can be
either command-line (CLI) or graphical (GUI).
• Managing user accounts and authentication.
• Handling user input/output, including terminal and graphical interfaces.
6. Network Communication:
• Managing network connections and protocols.
• Handling network configuration and routing.
• Enabling network services like web servers, email servers, and file sharing.
7. Security and Access Control:
• Enforcing user authentication and authorization.
• Implementing security policies and access control lists (ACLs).
• Monitoring and auditing system activities for security breaches.
8. File and Data Backup:
• Implementing backup and recovery mechanisms to protect against data loss.
• Scheduling automated backups of critical system and user data.
9. Error Handling and Logging:
• Recording system events, errors, and warnings in log files.
• Providing error messages and diagnostics to help users and administrators
troubleshoot issues.
10. Resource Allocation and Optimization:
• Managing system resources like CPU, memory, and disk space.
• Optimizing resource utilization to ensure efficient system performance.
11. System Updates and Maintenance:
• Installing and managing software updates, patches, and security fixes.
• Handling system configuration changes and maintenance tasks.
12. Power Management:
• Implementing power-saving features for laptops and mobile devices.
• Managing system sleep, hibernate, and power-off operations.
13. Virtualization and Containerization:
• Supporting virtual machines (e.g., with KVM) and containerization technologies
(e.g., Docker) for isolation and resource allocation.
14. Task Scheduling:
• Managing and scheduling automated tasks (cron jobs) at specific times or
intervals.
15. Interacting with Hardware:
• Providing drivers and interfaces for hardware components to ensure hardware
compatibility and functionality.
History and development of of Linux.
The history and development of Linux is a fascinating journey that began in the early 1990s. Here
is an overview of its key milestones and contributors:
1. Inception (1991): Linux was created by a Finnish computer science student named Linus
Torvalds. On August 25, 1991, Torvalds posted a message to the Usenet newsgroup
comp.os.minix, announcing the release of a free and open-source operating system kernel he had
been working on as a hobby. He initially named it "Freax" but later changed it to "Linux,"
combining his first name, Linus, with "Unix."
2. Early Development: Linux gained attention from early enthusiasts and developers who saw its
potential. It was distributed under the GNU General Public License (GPL), which allowed anyone
to view, modify, and distribute the source code. This licensing model contributed to Linux's rapid
growth.
3. GNU Project Collaboration: The Linux kernel was a critical component, but it lacked many
essential utilities and applications. To create a complete operating system, Linux was combined
with software developed by the Free Software Foundation's GNU Project. The resulting system
became known as "GNU/Linux," emphasizing the collaboration between the Linux kernel and
GNU software.
4. Growth of the Community: Linux quickly attracted a passionate and active community of
developers who contributed code, bug fixes, and documentation. This community-driven
development model played a pivotal role in Linux's success.
5. Distributions: Various groups and organizations started packaging Linux with GNU software
and creating Linux distributions. These distributions made it easier for users to install and use
Linux. Some early distributions included Slackware (1993), Debian (1993), and Red Hat (1994).
6. Kernel Development: Linus Torvalds continued to lead the development of the Linux kernel,
releasing new versions with improvements and features regularly. The kernel's codebase grew in
complexity and robustness.
7. Commercialization: Companies like Red Hat, SUSE, and Caldera (later known as SCO Group)
began to offer commercial support and services for Linux, targeting enterprise customers. This
helped legitimize Linux as an enterprise-grade operating system.
8. Linux in Servers: Linux found significant success in server environments due to its stability,
scalability, and cost-effectiveness. It became the platform of choice for web servers, data centers,
and cloud computing.
9. Linux on the Desktop: While Linux's primary success was in server and embedded systems, it
also gained popularity on the desktop, especially among technically inclined users. User-friendly
distributions like Ubuntu (2004) and Linux Mint (2006) aimed to make Linux more accessible to
the general public.
10. Mobile and Embedded Systems: Linux also found its way into mobile devices with the
development of the Android operating system (based on the Linux kernel), which became the
dominant platform for smartphones and tablets.
11. Linux in Supercomputing: Linux became the dominant operating system in the world of
high-performance computing (HPC), powering a large number of supercomputers and clusters.
12. Growth of the Ecosystem: Linux's success led to the development of a rich ecosystem of
open-source software, libraries, and tools, making it a versatile platform for various applications
and industries.
Linux Features
1. Multiuser capability: Multiple users can access the same system resources like memory, hard
disk, etc. But they have to use different terminals to operate.
2. Multitasking: More than one function can be performed simultaneously by dividing the CPU
time intelligently.
3. Portability: Portability doesn't mean it is smaller in file size or can be carried in pen drives or
memory cards. It means that it support different types of hardware.
4. Security: It provides security in three ways namely authenticating (by assigning password
and login ID), authorization (by assigning permission to read, write and execute) and
encryption (converts file into an unreadable format).
5. Live CD/USB: Almost all Linux distros provide live CD/USB so that users can run/try it without
installing it.
6. Graphical User Interface (X Window system): Linux is command line based OS but it can be
converted to GUI based by installing packages.
7. Support's customized keyboard: As it is used worldwide, hence supports different languages
keyboards.
8. Application support: It has its own software repository from where users can download and
install many applications.
9. File System: Provides hierarchical file system in which files and directories are arranged.
10. Open Source: Linux code is freely available to all and is a community based development
project.
1. Choose a Distribution: Select the Linux distribution you want to install (e.g., Ubuntu,
Fedora, Debian).
2. Download the ISO: Visit the distribution's official website and download the ISO file for
the version you want to install.
3. Create a Bootable USB: Use a tool like Rufus (Windows) or Etcher (Windows, macOS,
Linux) to create a bootable USB drive from the ISO.
4. Boot from USB: Insert the USB drive into your computer and boot from it. This might
involve changing the boot order in your BIOS settings.
5. Start Installation: Once booted, you'll be presented with the distribution's live
environment. You can choose to try it out or directly start the installation process.
6. Language and Localization: Choose your language, time zone, and keyboard layout.
7. Partitioning: Decide how to partition your hard drive. You can let the installer do it
automatically or choose manual partitioning for more control.
8. User Account: Create a user account and set a password. This will be your main account
for using the system.
9. Installation Location: Select the partition where you want to install Linux.
10. Configure Network: Connect to Wi-Fi or Ethernet if required.
11. Package Selection: Choose the software packages you want to install. You can select
from predefined setups like "minimal," "desktop," etc.
12. GRUB Installation: Choose where to install the GRUB bootloader. This is usually the main
hard drive.
13. Complete Installation: The installer will copy files and set up your system. Once done,
you'll be prompted to reboot.
14. Remove Installation Media: Remove the USB drive and reboot your computer.
15. First Boot: Upon reboot, the GRUB menu should appear. Select the Linux distribution to
start it.
16. Initial Setup: Follow the on-screen prompts to complete the initial setup, including
configuring your user account and updating the system.
1. Kernel:
• Linux: Linux is built on the Unix-like Linux kernel, which is open-source and
maintained by a community of developers.
• Windows: Windows uses a closed-source kernel developed by Microsoft.
2. Source Code:
• Linux: Linux is open-source, meaning its source code is freely available,
modifiable, and redistributable.
• Windows: Windows is proprietary, and its source code is not publicly accessible.
3. Licensing:
• Linux: Most Linux distributions are distributed under various open-source licenses
(e.g., GNU General Public License), allowing users to use, modify, and distribute
the software freely.
• Windows: Windows is commercial software, and users must purchase licenses for
its use. Microsoft offers various editions with different features and pricing.
4. User Interface:
• Linux: Linux provides a wide range of desktop environments (e.g., GNOME, KDE,
Xfce) and window managers, offering flexibility in user interface customization.
• Windows: Windows has a consistent user interface across its versions, with the
Start menu and taskbar being common elements.
5. Software Availability:
• Linux: Linux has a rich repository of open-source software available through
package managers, but some proprietary software may not have native Linux
versions.
• Windows: Windows has a vast library of commercial software, and many
applications are specifically developed for the Windows platform.
6. Software Installation:
• Linux: Software installation is typically done through package managers like APT
(Debian/Ubuntu) or YUM (Red Hat/Fedora), which handle dependencies and
updates.
• Windows: Windows software is often installed using standalone installers or
executable files, which may require manual updates and management.
7. Security:
• Linux: Linux is known for its strong security features, including user privileges,
robust permission systems, and a lower susceptibility to malware compared to
Windows.
• Windows: Windows has historically been a target for malware due to its
popularity, but Microsoft has made significant security improvements in recent
years.
8. Customization and Control:
• Linux: Linux offers advanced customization and control over the system, making it
a favorite for power users and system administrators.
• Windows: While Windows allows some customization, it's generally more locked
down compared to Linux.
9. Compatibility:
• Linux: Linux can run on a wide range of hardware, including older machines and
embedded systems.
• Windows: Windows has specific hardware requirements, and not all versions are
compatible with older hardware.
10. Support and Documentation:
• Linux: Linux distributions often have strong community support and extensive
online documentation.
• Windows: Windows benefits from official Microsoft support and a wealth of
online resources.
1. Origins:
• Unix: Unix is one of the earliest operating systems developed at AT&T's Bell Labs
in the late 1960s. It served as the foundation for many modern operating systems,
including Linux.
• Linux: Linux, on the other hand, is a Unix-like operating system developed by
Linus Torvalds in 1991. It was inspired by Unix but is not a direct derivative.
2. Licensing:
• Unix: Unix-based operating systems often have proprietary versions, and the
term "Unix" itself is a registered trademark. These systems typically require
licensing fees.
• Linux: Linux is open-source, distributed under various open-source licenses (e.g.,
GNU GPL). This means that anyone can view, modify, and distribute its source
code freely.
3. Development Model:
• Unix: Development of Unix-based operating systems is typically controlled by a
single organization or company (e.g., AIX by IBM, Solaris by Oracle).
• Linux: Linux development is a collaborative effort involving a global community
of volunteers and organizations. There is no single controlling entity.
4. Variety of Distributions:
• Unix: Unix-based operating systems have different flavors (e.g., AIX, HP-UX,
Solaris), each tailored for specific hardware or use cases.
• Linux: Linux has numerous distributions (e.g., Ubuntu, CentOS, Fedora) with
various package managers and configurations, catering to a wide range of
purposes and preferences.
5. Kernel:
• Unix: Unix systems use their own proprietary kernels (e.g., Solaris uses the Solaris
kernel).
• Linux: Linux uses the Linux kernel, which is open-source and maintained by the
Linux community.
6. Compatibility:
• Unix: Unix-based systems can vary significantly between versions, making it less
compatible between different Unix flavors.
• Linux: Linux distributions often adhere to open standards, making it easier to
develop software that runs across multiple distributions.
7. Commercial vs. Free:
• Unix: Many Unix variants are commercial and require licensing fees. Some are
free for certain use cases (e.g., FreeBSD).
• Linux: Most Linux distributions are freely available, reducing software costs for
businesses and individuals.
8. Community and Support:
• Unix: Commercial Unix systems typically offer official support, while community
support varies depending on the Unix variant.
• Linux: Linux has strong community support, with extensive online resources and
a wide range of community-driven forums and documentation.
Certainly, here are some basic Linux commands that can help you navigate and interact with the
system:
1. pwd (Print Working Directory):
• Displays the current directory path.
2. ls (List):
• Lists files and directories in the current directory.
• Common options:
• -l : Long format (includes permissions, owner, group, size, date).
• -a : List hidden files (those starting with a dot).
3. cd (Change Directory):
• Changes your current directory.
• Usage: cd directory_name or cd /path/to/directory
4. mkdir (Make Directory):
• Creates a new directory.
• Usage: mkdir directory_name
5. rmdir (Remove Directory):
• Removes an empty directory.
• Usage: rmdir directory_name
6. touch:
• Creates an empty file or updates the access and modification times of an existing
file.
• Usage: touch file_name
7. rm (Remove):
• Deletes files or directories.
• Usage for files: rm file_name
• Usage for directories and their contents: rm -r directory_name
8. cp (Copy):
• Copies files or directories.
• Usage: cp source destination
9. mv (Move):
• Moves or renames files or directories.
• Usage for moving: mv source destination
• Usage for renaming: mv old_name new_name
10. cat (Concatenate):
• Displays the contents of a file.
• Usage: cat file_name
11. less:
• Allows you to view text files one screen at a time.
• Usage: less file_name
• To navigate, use the arrow keys or type q to exit.
12. head and tail:
• Display the beginning or end of a file, respectively.
• Usage: head file_name or tail file_name
13. grep (Global Regular Expression Print):
• Searches for text patterns within files.
• Usage: grep pattern file_name
14. chmod (Change Mode):
• Modifies file or directory permissions.
• Usage: chmod permissions file_name
• Example: chmod +x script.sh makes a script executable.
15. chown (Change Owner):
• Changes the owner of a file or directory.
• Usage: chown new_owner file_name
16. df (Disk Free):
• Shows disk space usage.
• Usage: df -h for a human-readable output.
17. du (Disk Usage):
• Displays the file and directory space usage.
• Usage: du -h for a human-readable output.
18. ps (Process Status):
• Lists running processes.
• Usage: ps aux for a detailed list.
19. kill:
• Terminates processes by their process ID (PID).
• Usage: kill PID
20. shutdown and reboot:
• Shuts down or reboots the system.
• Usage: shutdown or reboot
1. / (Root Directory):
• The top-level directory that contains all other directories and files.
• Symbolized as / , and it's the starting point of the directory structure.
2. /bin (Binary Binaries):
• Contains essential binary executables required for system recovery and
maintenance. These are typically commands used in single-user mode.
3. /boot (Boot Files):
• Contains bootloader files, kernel images, and other files necessary for the initial
boot process.
4. /dev (Device Files):
• Contains device files that represent hardware devices, including disks, partitions,
and peripherals.
5. /etc (System Configuration Files):
• Houses system-wide configuration files and shell scripts that control system
behavior and configuration.
6. /home (User Home Directories):
• Contains home directories for regular users. Each user typically has a subdirectory
here for their personal files and settings.
7. /lib and /lib64 (Shared Libraries):
• These directories hold shared libraries and kernel modules that are required for
system boot and the functioning of programs in /bin and /sbin .
8. /media and /mnt (Mount Points):
• These directories are used as mount points for removable media, such as USB
drives and network shares.
9. /opt (Optional Software):
• Used for the installation of optional, third-party software packages. Typically,
software not managed by the package manager is placed here.
10. /proc (Process Information):
• Provides a virtual filesystem that presents system and process information as files.
You can view and manipulate kernel parameters and process data here.
11. /root (Root User Home):
• The home directory for the root user (superuser).
12. /sbin (System Binaries):
• Contains essential system binaries used for system administration tasks, typically
reserved for the root user.
13. /srv (Service Data):
• Used for data files associated with services provided by the system.
14. /tmp (Temporary Files):
• Stores temporary files and directories that are meant to be used by applications
and users.
15. /usr (User Binaries and Data):
• Contains user-level commands, libraries, and data files. It's often the largest
portion of the filesystem.
16. /var (Variable Files):
• Holds variable data files like logs, spool files, and temporary files generated by
various system processes.
17. /run (Runtime Data):
• Contains runtime data for system services, such as PID files and sockets.
1. CPU:
•A modern processor, such as an Intel Core i3 or AMD Ryzen 3, should suffice for
most Linux distributions.
2. RAM (Memory):
• At least 1 GB of RAM is recommended for running lightweight desktop
environments or server installations.
• For a more comfortable desktop experience and multitasking, consider 4 GB or
more.
3. Storage:
• For the base installation of the Linux operating system, you'll need a minimum of
10-20 GB of disk space.
• Additional space is required for user data, software installations, and other files. A
larger hard drive or SSD is advisable for general use.
4. Graphics:
• For most Linux distributions, basic integrated graphics are sufficient.
• If you plan to use resource-intensive graphical applications or gaming, consider a
dedicated graphics card with appropriate driver support.
5. Display:
• A standard VGA, DVI, or HDMI-compatible monitor should work with most Linux
distributions.
• Linux generally supports a wide range of display resolutions and configurations.
6. Network Connectivity:
• An Ethernet port (wired) or Wi-Fi adapter (wireless) for internet connectivity.
• Most Linux distributions provide support for a wide range of network hardware.
7. Input Devices:
• Keyboard and mouse or other input devices for user interaction.
8. Optical Drive (Optional):
• An optical drive (DVD-ROM or Blu-ray) may be necessary for installation if you're
not using a USB bootable device.
9. Sound Card (Optional):
• A built-in or external sound card is needed for audio output and input.
10. USB Ports:
• USB ports for connecting peripherals and for creating bootable USB drives for
installation.
9. touch:
• Creates an empty file or updates the access and modification times of an existing
file.
• Usage: touch file_name
10. cat (Concatenate):
• Displays the contents of a file.
• Usage: cat file_name
11. more and less :
• Allow you to view text files one screen at a time.
• Usage: more file_name or less file_name
• To navigate in less , use the arrow keys or type q to exit.
12. head and tail :
• Display the beginning or end of a file, respectively.
• Usage: head file_name or tail file_name
13. grep (Global Regular Expression Print):
• Searches for text patterns within files.
• Usage: grep pattern file_name
14. chmod (Change Mode):
• Modifies file or directory permissions.
• Usage: chmod permissions file_name
15. chown (Change Owner):
• Changes the owner of a file or directory.
• Usage: chown new_owner file_name
16. wc (Word Count):
• Counts lines, words, and characters in a file.
• Usage: wc file_name
17. file :
• Determines the file type.
• Usage: file file_name
18. ln (Link):
• Creates hard or symbolic links to files.
• Usage: ln -s source_file link_name for symbolic links.
1. bc (Basic Calculator):
• A command-line calculator that supports basic arithmetic operations, advanced
functions, and more.
• Usage: Run bc and then enter mathematical expressions.
2. expr (Expression Evaluator):
• Evaluates expressions and performs arithmetic operations.
• Usage: expr 5 + 3
3. awk:
• A versatile text-processing tool that can also perform arithmetic calculations.
• Usage: awk 'BEGIN {print 5 + 3}'
4. python or python3 (Python Interpreter):
• You can perform complex mathematical calculations using Python, which is often
pre-installed on Linux systems.
• Usage: Run python or python3 to enter the Python interpreter and perform
calculations.
5. perl (Perl Interpreter):
• Perl can handle various mathematical operations and is often used for text
processing as well.
• Usage: Run perl -e 'print 5 + 3'
6. dc (Desk Calculator):
• A reverse-polish notation calculator for performing arithmetic calculations.
• Usage: Run dc and then enter expressions in reverse-polish notation.
7. units (Unit Conversion):
• Allows you to perform unit conversions and mathematical calculations with
different units.
• Usage: Run units and then enter conversion or calculation queries.
8. calc (Console Calculator):
• A simple, easy-to-use calculator with a basic command-line interface.
• Usage: Run calc to start the calculator.
9. maxima (Computer Algebra System):
• A sophisticated computer algebra system for symbolic and numerical
mathematical calculations.
• Usage: Install and run maxima to use it.
10. octave (GNU Octave):
• An open-source alternative to MATLAB, suitable for numerical computations.
• Usage: Install and run octave to perform mathematical calculations.
11. R (R Statistical Computing):
• A powerful statistical computing language and environment.
• Usage: Install and run R for advanced statistical and mathematical analysis.
12. gnuplot (Plotting Utility):
• While primarily for creating plots and graphs, it can also perform simple
mathematical calculations.
• Usage: Run gnuplot and enter expressions
1. Local Login:
• To log in to a Linux system locally, you need to have a user account on that
system.
• At the system's login screen or terminal, enter your username and password.
• After successful authentication, you will be granted access to the system.
2. Local Logout:
• To log out of your local session, you can usually use the exit command or simply
close the terminal window or graphical session.
Remote Login:
1. cal (Calendar):
• The cal command displays a calendar for a specific month and year or for the
current month.
• Usage:
• cal: Displays the calendar for the current month.
• cal month year : Displays the calendar for a specific month and year.
2. date (Date and Time):
• The date command displays the current date and time.
• Usage:
• date : Displays the current date and time in the default format.
• date "+%format" : Customizes the output format. For example, date "+%Y-%m-
%d %H:%M:%S" will display the date and time in a specific format.
3. wc (Word Count):
• The wc command is used to count lines, words, and characters in a text file.
• Usage:
• wc filename : Displays the line count, word count, and character count for
the specified file.
• wc -l filename : Displays only the line count.
• wc -w filename : Displays only the word count.
• wc -c filename : Displays only the character count.
4. who (Logged-In Users):
• The who command displays a list of users who are currently logged into the
system.
• Usage:
• who: Lists information about currently logged-in users, including their
usernames, terminal IDs, login times, and originating IP addresses if
available.
• who am i : Shows information about your own login session.
1.head:
The head command is used to display the beginning (head) of a text file or input from the standard
input.
By default, it displays the first 10 lines of a file.
Usage:
2.tail:
The tail command displays the end (tail) of a text file or input from the standard input.
Usage:
3.sort:
The sort command is used to sort lines of text files alphabetically or numerically.
Usage:
sort file_name: Sort the lines of the specified file in ascending order.
4.grep:
The grep command is a powerful tool for searching text using regular expressions.
It searches for a specified pattern (regular expression) in a file or input and displays matching lines.
Usage:
grep pattern file_name: Search for lines containing the specified pattern in the file.
grep -v pattern file_name: Display lines that do not contain the pattern.
grep -r pattern directory: Recursively search for the pattern in files within a directory.
Boot Loaders (LILO and GRUB)
Boot loaders are essential components of the Linux operating system responsible for loading the
kernel into memory and initializing the system during the boot process. Two commonly used boot
loaders in Linux are LILO (LInux LOader) and GRUB (GRand Unified Bootloader). However, it's worth
noting that as of my last knowledge update in September 2021, GRUB is more commonly used and
recommended over LILO, which has largely fallen out of favor. Let's briefly discuss both boot loaders:
- LILO was one of the earliest boot loaders used in Linux systems but has largely been replaced by
GRUB due to its limitations.
- It requires manual updating whenever there are changes to the kernel or boot configuration.
- LILO had a simple configuration but was less flexible compared to GRUB.
- One significant limitation is that it didn't support booting from multiple operating systems easily.
```plaintext
boot=/dev/sda
root=/dev/sda1
image=/boot/vmlinuz
label=linux
```
- GRUB is the most widely used and recommended boot loader in Linux distributions.
- The configuration file for GRUB is typically located at `/etc/default/grub`, and you can regenerate
the bootloader configuration using the `update-grub` or `grub-mkconfig` command.
- GRUB allows you to boot multiple operating systems and has a graphical menu interface.
- It supports a wide range of file systems and can load kernels and initramfs images from various
locations.
Example of a simple GRUB configuration:
```plaintext
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
```
To install or update GRUB, you can use commands like `grub-install` or `update-grub` (or `grub-
mkconfig`) depending on your Linux distribution. It's important to keep in mind that the
configuration and usage of boot loaders can vary between Linux distributions, so you should consult
your distribution's documentation for specific instructions.
System Initiazation
System initialization in Linux involves a series of steps and processes that occur when the computer is
powered on or restarted. These processes are responsible for initializing hardware, starting essential
system services, and bringing the operating system to a fully functional state. The exact details of the
initialization process can vary depending on the Linux distribution, but here's a general overview of
the common stages in the system initialization process:
- When you power on your computer, the Basic Input/Output System (BIOS) or Unified Extensible
Firmware Interface (UEFI) firmware is the first software that runs.
- The firmware performs a Power-On Self-Test (POST) to check the hardware's integrity and
configuration.
- It then locates the boot device (usually the hard drive or SSD) and loads the bootloader.
- The boot loader, like GRUB, is responsible for loading the Linux kernel and initializing the system.
- The bootloader menu allows you to select different operating systems if multiple OSes are
installed.
- Once a selection is made, the bootloader loads the kernel and an initial RAM disk
(initrd/initramfs).
3. **Linux Kernel Initialization**:
- The kernel is responsible for initializing essential hardware components, such as CPU, memory,
and device drivers.
- It mounts the root file system, which contains the core OS files.
- The kernel also starts the `init` process, which serves as the ancestor of all other processes in the
system. In modern Linux distributions, `init` is often replaced by a more advanced process manager
like `systemd`.
- Once `init` or a modern init system like `systemd` starts, it begins initializing user space
components.
- `systemd`, for example, can start various system services in parallel, improving boot times.
- Other init systems, like SysV init, follow a more sequential approach, starting scripts from the
`/etc/rc.d` or `/etc/init.d` directories.
- With `systemd`, the concept of runlevels is replaced with "targets," which are sets of services that
need to be started.
- Different targets are used for different system states (e.g., multi-user.target for normal operation).
- You can switch between targets using commands like `systemctl isolate` or `systemctl set-default`.
- Once the system initialization is complete, a login manager (e.g., GDM, LightDM) may start,
presenting the graphical login screen.
- Users can log in using their credentials, or they can log in through a terminal (TTY) if they prefer a
text-based interface.
- Additional services and daemons (e.g., network services, printing services) may also start as
needed.
Inittab
The `inittab` file in Linux is a configuration file that was traditionally used to control the initialization
and management of the system's init process. However, it's important to note that the use of
`inittab` has become less common in modern Linux distributions, especially those using `systemd` as
the init system. `systemd` and other modern init systems have replaced many of the traditional
functionalities of `inittab` with their own configuration files and mechanisms.
Here's a brief overview of what `inittab` used to do and how it was structured in traditional SysV init
systems:
- `inittab` was primarily used to define how the init process (usually `init`) manages the system's
runlevels and services.
- Runlevels represent different system states, such as single-user mode, multi-user mode, or
shutdown.
2. **Syntax**:
- Entries in the `inittab` file were organized into lines, each specifying an action to be taken by the
init process.
```
id:runlevels:action:process
```
- `runlevels`: Specifies the runlevels for which the action should be executed.
- `action`: Defines the action to take (e.g., `initdefault`, `respawn`, `wait`, `powerwait`).
3. **Common Actions**:
- `initdefault`: Specifies the default runlevel the system should boot into.
- `wait`: Starts a process once when entering a runlevel and waits for it to complete.
```plaintext
id:3:initdefault:
```
rc.sysinit
The `rc.sysinit` script in Linux is a part of the System V initialization (SysV init) system, which is used in
some older Linux distributions for managing the startup and shutdown processes. This script is
typically responsible for performing various system initialization tasks that are required during the
boot process, such as setting up hardware devices, mounting filesystems, and configuring system
settings.
Here are some common tasks that the `rc.sysinit` script might handle:
1. **Filesystem Mounting**: It mounts essential filesystems like root (`/`), `/proc`, `/sys`, and `/dev`.
2. **Device Initialization**: It initializes hardware devices and loads necessary kernel modules for
devices that are detected during the boot process.
4. **Checking and Repairing Filesystems**: It may run filesystem checks (e.g., `fsck`) to ensure
filesystem integrity and may attempt repairs if needed.
5. **Initializing Networking**: It may configure basic network settings and start network services.
6. **Setting System Time**: It sets the system time and date.
8. **Running System Initialization Scripts**: It may execute other initialization scripts or tasks that
are required before the system reaches a usable state.
The specific contents and tasks of `rc.sysinit` can vary between different Linux distributions and
versions. In some modern Linux distributions, especially those using `systemd` as the init system, the
responsibilities of `rc.sysinit` have been replaced by systemd unit files and other components.
It's worth noting that as Linux distributions have evolved, many have moved away from the
traditional SysV init system in favor of more modern init systems like `systemd`. Therefore, the
presence and usage of `rc.sysinit` may vary, and it might not be found on systems using newer init
systems.
Rc
In Linux, "rc" typically stands for "run commands" or "runtime configuration," and it is often used to
refer to various scripts and configuration files that control the behavior of the system or specific
programs. Here are some common uses and examples of "rc" in Linux:
1. **rc.local**: This is a script that runs at the end of the system boot process. You can use it to
execute custom commands or scripts when your Linux system starts up. The path to this file is usually
`/etc/rc.local` or `/etc/rc.d/rc.local`.
2. **init.d scripts**: In older Linux distributions that use the SysV init system, you can find "rc"
scripts in the `/etc/init.d/` directory. These scripts are used to start, stop, and manage system
services.
3. **rc.d directories**: On some Linux distributions like Slackware, you'll find directories named
`rc.d` that contain various runlevel-specific scripts. These scripts control the behavior of the system
at different runlevels (e.g., single-user mode, multi-user mode).
4. **~/.bashrc**: This is a user-specific configuration file for the Bash shell. It is executed each time a
user logs in, and it allows you to customize your shell environment by defining aliases, setting
environment variables, and more.
5. **~/.vimrc**: If you're a Vim user, you can customize the behavior of the Vim text editor by
creating a `~/.vimrc` file in your home directory. This file can contain various Vim configuration
options and customizations.
6. **Xresources**: The X Window System uses an `.Xresources` file to store configuration settings for
X applications like terminal emulators. You can customize the appearance and behavior of these
applications by editing this file.
7. **systemd service unit files**: In modern Linux distributions that use systemd as the init system,
service unit files with the `.service` extension are used to define and configure system services. These
files are typically located in directories like `/etc/systemd/system/`.
- CUPS uses the `/var/spool/cups` directory as its print spool directory by default. You can find print
jobs in subdirectories like `c` (completed jobs), `d` (pending jobs), and `t` (temporary files).
2. **LPRng**:
- LPRng, an alternative printing system, typically uses the `/var/spool/lpd` directory as its print
spool directory.
- In some older Linux systems or configurations, you might find the print spool directory in
`/var/spool/lp` or `/var/spool/lpd`.
To view the contents of the print spool directory, you can use terminal commands like `ls` or `lpq`.
For example, to list the print jobs in the CUPS spool directory, you can use the following command:
```bash
ls /var/spool/cups
```
To view the print queue and status of print jobs, you can use the `lpq` command. For example:
```bash
lpq
```
1. **lp Command**:
The `lp` command is a basic way to send files to a printer in Linux. You can use it like this:
```bash
lp <filename>
```
Replace `<filename>` with the path to the file you want to print. By default, this will send the file to
the default printer. You can specify a different printer using the `-d` option, like so:
```bash
lp -d <printer_name> <filename>
```
To view the print queue and check the status of your print job, you can use the `lpq` command:
```bash
lpq
```
2. **lpr Command**:
The `lpr` command is another way to send files to a printer. It works similarly to `lp`:
```bash
lpr <filename>
```
To specify a printer:
```bash
```
```bash
lpq
```
If you are using the Common Unix Printing System (CUPS), you can access the CUPS web interface
through your web browser. Typically, it's available at `http://localhost:631`. From there, you can add
and manage printers, view the print queue, and submit print jobs.
If you're using a Linux distribution with a GNOME or KDE desktop environment, you can often send
files to the printer directly from the file manager or document viewer applications. Right-click on a
file and look for a "Print" or "Send to Printer" option.
Editors
In Linux, there are several text editors available, each with its own features and capabilities. Choosing
the right text editor depends on your specific needs and preferences. Here are some commonly used
text editors in Linux:
1. **Nano**: Nano is a simple and beginner-friendly text editor. It's easy to use and comes pre-
installed on many Linux distributions. Nano uses keyboard shortcuts for common tasks and displays
them at the bottom of the screen.
Usage:
```
nano filename
```
2. **Vim**: Vim is a highly configurable and powerful text editor. It has a steeper learning curve but
offers extensive customization options and powerful features for advanced users. Vim operates in
different modes, including insert mode and command mode.
Usage:
```
vim filename
```
3. **Emacs**: Emacs is another highly customizable text editor with a variety of extensions and add-
ons. It's known for its extensibility and can be used for more than just text editing; it can even
function as an integrated development environment (IDE) for certain programming languages.
Usage:
```
emacs filename
```
4. **Gedit**: Gedit is a simple and user-friendly text editor that comes with the GNOME desktop
environment. It's ideal for basic text editing tasks and is easy to use for beginners.
Usage:
```
gedit filename
```
5. **Kate**: Kate is the default text editor for the KDE desktop environment. It offers a wide range of
features, including syntax highlighting, code folding, and extensive customization options.
Usage:
```
kate filename
```
6. **Sublime Text**: While Sublime Text is not open source, it's a popular and powerful text editor
with a sleek user interface and a wide array of plugins and themes available. It's widely used by
developers for various programming tasks.
Usage:
```
subl filename
```
7. **Atom**: Atom is an open-source text editor developed by GitHub. It's highly customizable and
has a vibrant community that creates packages and themes to extend its functionality.
Usage:
```
atom filename
```
8. **Visual Studio Code (VSCode)**: Although developed by Microsoft, Visual Studio Code is a
popular cross-platform text editor widely used in the Linux community. It offers excellent support for
various programming languages and extensive extensions.
Usage:
```
code filename
```
Use of vi
VI is a text editor available on many Unix-like operating systems, including Linux. It's a powerful and
efficient text editor, although it has a somewhat steep learning curve. VI operates in different modes,
which can be confusing for newcomers, but once you get the hang of it, it's a very versatile tool for
text editing. Here are some common use cases for VI in Linux:
You can create and edit text files using VI. To create a new file or edit an existing one, open a
terminal and type:
```
vi filename
```
2. **Inserting Text**:
To insert text into a file, you need to be in the "Insert" mode. Press `i` to enter insert mode. Then,
you can type and edit the text as you normally would in any other text editor.
3. **Saving Changes**:
To save your changes, first exit insert mode by pressing the `Esc` key. Then, type `:w` and press
`Enter`. This writes the changes to the file without quitting VI.
4. **Quitting VI**:
To exit VI, press `Esc` to ensure you are in command mode, then type `:q` and press `Enter`. If
you've made changes to the file, VI will not allow you to quit without saving the changes. To force
quit without saving, use `:q!`.
To save your changes and quit at the same time, use `:wq` and press `Enter`.
In command mode, you can move the cursor using arrow keys or various keyboard shortcuts. For
example, `h` moves left, `j` moves down, `k` moves up, and `l` moves right.
7. **Deleting Text**:
In command mode, you can delete characters or lines using `x` (delete character) or `dd` (delete
line).
8. **Searching Text**:
To search for text within a file, press `/` in command mode, then type the text you want to find and
press `Enter`. To find the next occurrence, press `n`.
9. **Replacing Text**:
In command mode, you can replace text using `:s/old_text/new_text/g`. This will replace all
occurrences of `old_text` with `new_text` in the entire file.
You can open multiple files in VI by specifying their names when you start VI. You can switch
between open files using `:n` to go to the next file and `:N` to go to the previous file.
Features of vi
VI is a widely used text editor in Linux and Unix-like operating systems. While it may appear
minimalistic compared to modern graphical text editors, it offers a range of powerful features for
efficient text editing once you get familiar with its commands and modes. Here are some of the key
features of VI:
1. **Modal Editing**: VI operates in different modes: Normal (command) mode, Insert mode, and
Visual mode. This allows you to perform various tasks without needing a large number of keyboard
shortcuts.
2. **Small and Fast**: VI is a lightweight text editor and loads quickly, making it suitable for use in a
terminal environment.
3. **Syntax Highlighting**: Some versions of VI, such as Vim (Vi IMproved), support syntax
highlighting for various programming languages, making code editing more efficient.
4. **Customization**: VI is highly customizable through configuration files (`.vimrc` for Vim) and
plugins. You can tailor it to your specific needs, adding features and functionality as desired.
5. **Powerful Search and Replace**: VI provides powerful search and replace capabilities. You can
search for text using regular expressions and replace text efficiently.
6. **Undo and Redo**: VI allows you to undo and redo changes made to a file using the `u` and `Ctrl-
R` commands in Normal mode.
7. **Multiple Buffers and Windows**: You can open multiple files simultaneously and switch
between them using buffers and split windows within VI, which is particularly useful for comparing
or editing multiple files.
8. **Macros**: VI allows you to record and replay macros, which are sequences of commands. This
can automate repetitive tasks.
9. **Visual Selection**: In Visual mode, you can select and manipulate text blocks easily, such as
copying, cutting, or indenting.
10. **Line Numbers**: VI can display line numbers, making it easier to navigate and reference
specific lines in a file.
11. **File Navigation**: VI provides commands for quickly navigating within a file, jumping to
specific line numbers, or moving to the beginning or end of a file.
12. **Abbreviations and Autocompletion**: You can define abbreviations and use autocompletion
features to speed up typing repetitive code or text.
13. **Integration with External Tools**: VI can integrate with external tools for tasks like spell
checking, version control, and running scripts from within the editor.
14. **Wide Platform Support**: VI is available on various Unix-like systems, including Linux, BSD, and
macOS, making it a consistent choice across different platforms.
15. **Extensive Online Documentation**: VI and Vim come with comprehensive documentation
accessible via `:help` within the editor, providing detailed information on commands and features.
16. **Large and Active Community**: VI has a devoted user community, which means you can find a
wealth of resources, tutorials, and plugins to enhance your editing experience.
VI basics
Using VI (or Vim, which is an improved version of Vi) in Linux can be a bit intimidating for beginners
due to its modal nature and unique command structure. However, it's a powerful text editor once
you get the hang of it. Here are some basic VI commands and concepts to help you get started:
```
vi filename
```
Replace `filename` with the name of the file you want to edit.
**2. Modes:**
- **Normal Mode**: The default mode where you can navigate, delete, and perform various
operations on text using single-letter commands.
- **Insert Mode**: This mode is for inserting or editing text. Press `i` to enter insert mode before
typing text.
- **Visual Mode**: This mode is for selecting text. Press `v` to enter visual mode, and then you can
select text using navigation keys.
- `k`: Move up
- `{line number}G`: Move to a specific line number (e.g., `10G` goes to line 10)
- `o`: Open a new line below the current line and enter insert mode
- `O`: Open a new line above the current line and enter insert mode
- In Normal Mode, to save changes, press `:` to enter command mode, then type `w` and press
`Enter`. This is `:w`.
- To save changes and quit, press `:` to enter command mode, then type `wq` and press `Enter`. This
is `:wq`.
- To quit without saving, press `:` to enter command mode, then type `q!` and press `Enter`. This is
`:q!`.
**6. Searching:**
- In Normal Mode, press `/` to start a search. Type the text you want to search for and press `Enter`.
Use `n` to find the next occurrence and `N` to find the previous occurrence.
**7. Deleting Text:**
- In Normal Mode, use `x` to delete the character under the cursor.
- Use `p` to paste the copied text below the cursor or `P` to paste above the cursor.
1. **Normal Mode**: This is the default mode when you open VI. In Normal Mode, you can navigate
the text, delete, copy, paste, and perform various other text manipulation tasks using single-letter
commands. To enter Normal Mode from any other mode, press the `Esc` key.
- `k`: Move up
- `D`: Delete from the cursor position to the end of the line
- `/`: Start a forward search; type the text to search for and press `Enter`
2. **Insert Mode**: In this mode, you can type and edit text as you would in any other text editor. To
enter Insert Mode, press one of the following keys while in Normal Mode:
- `o`: Open a new line below the current line and enter insert mode
- `O`: Open a new line above the current line and enter insert mode
3. **Visual Mode**: This mode is used for selecting text. It allows you to highlight a block of text for
copying, cutting, or other operations. To enter Visual Mode, press `v` while in Normal Mode. Then,
use the navigation keys to select text. Once text is selected, you can perform actions on it.
4. **Command-Line Mode**: In this mode, you can enter various commands for saving, quitting,
searching, and other advanced operations. To enter Command-Line Mode, press `:` while in Normal
Mode. Some common commands in this mode include:
To switch between these modes, you'll often start in Normal Mode, enter Insert Mode to edit text,
and then return to Normal Mode when you're done editing. You can use Visual Mode to select text in
Normal Mode, and Command-Line Mode for various file operations and searching.
Command mode-Curser
movements(k,j,h,I),delete(character,line,word),Screen up,down use of
repeat factor,Joining lines(J)
In VI or Vim, you can perform various cursor movements, text deletions, screen navigation, and
joining lines in Normal Mode (also known as Command Mode). Here are some common commands
and operations:
**Cursor Movements:**
- `0` (zero): Move the cursor to the beginning of the current line.
- `^`: Move the cursor to the first non-blank character of the current line.
- `{number}G`: Move the cursor to a specific line number (e.g., `10G` moves to line 10).
**Deletions:**
- `x`: Delete the character under the cursor.
- `{number}dd`: Delete a specific number of lines (e.g., `3dd` deletes three lines).
- `dw`: Delete from the cursor position to the end of the current word.
- `d{motion}`: Delete text specified by a motion command (e.g., `d2w` deletes two words).
**Screen Navigation:**
- `Ctrl-f` (or `Page Down` key): Scroll forward one screen (page down).
- `Ctrl-b` (or `Page Up` key): Scroll backward one screen (page up).
**Repeat Factor:**
- You can use a number before many commands to repeat the command that many times. For
example, `3dd` deletes three lines, and `4j` moves the cursor four lines down.
**Joining Lines:**
- `J`: Join (or merge) the current line with the next line. It removes the newline character between
them. Place the cursor on the first line you want to join and press `J`. For example, if you have two
lines:
```
Line 1
Line 2
```
Placing the cursor on "Line 1" and pressing `J` will result in:
```
Line 1 Line 2
```
Input Mode-switching with (I,o,r,s,a,I,O,R,S) Ex mode-saving(w,x,q)
In VI or Vim, you can switch between different modes to perform various text editing tasks. The
modes for entering and exiting text are crucial to efficient editing. Here are the Input Mode
commands and the Ex mode commands:
5. `o`: Open a new line below the current line and enter Insert mode.
6. `O`: Open a new line above the current line and enter Insert mode.
7. `r`: Replace the character under the cursor with a new character. After pressing `r`, type the
replacement character.
8. `R`: Enter Replace mode, which allows you to overwrite text as you type.
9. `s`: Substitute the character under the cursor with a new character and enter Insert mode.
These commands allow you to switch between Normal Mode and Insert Mode, as well as perform
various text insertion and replacement actions.
1. `:w` or `:write`: Save the changes made to the file. For example, `:w` saves the file.
2. `:x` or `:save` or `:xit`: Save and exit the file. These commands are equivalent to `:wq` (write and
quit).
3. `:q` or `:quit`: Quit Vim. If you have unsaved changes, Vim will prevent you from quitting unless
you use `!` to force quit (e.g., `:q!`).
6. `:w {filename}`: Save the file with a new name or path, effectively making a copy.
7. `:e {filename}`: Open a new file for editing. This discards unsaved changes in the current file.
8. `:e!`: Revert changes made to the current file since the last save.
Ex mode commands are used to manage files, save changes, and exit Vim. You typically enter Ex
mode by pressing `:` while in Normal Mode. Then, you can type the desired Ex command followed by
`Enter`.
These are some of the basic Input Mode switching and Ex mode commands in Vim. Vim has a wide
range of additional commands and capabilities for advanced text editing and file management, so
you can explore further as you become more comfortable with the editor.
Suppose you have a file named `source.txt`, and you want to copy lines containing a specific pattern
to a new file named `destination.txt`. You can use the `grep` command in combination with `cat` to
achieve this:
```bash
```
This command will take the contents of `source.txt`, search for lines containing "pattern," and then
write those lines to `destination.txt`.
The `sed` command allows you to perform various text transformations, including copying lines that
match a pattern to another file. For example, to copy lines containing "pattern" from `source.txt` to
`destination.txt`:
```bash
```
The `-n` option suppresses automatic printing, and the `/pattern/p` command tells `sed` to print lines
that match the pattern.
You can also use `awk` to select and copy lines based on specific criteria. For example, to copy lines
containing "pattern" from `source.txt` to `destination.txt`:
```bash
```
If you prefer to use a text editor, such as Vi or Vim, you can manually select and copy lines:
```bash
vi source.txt
```
4. Use the navigation keys (e.g., `j` to move down) to select the lines you want to copy.
```bash
vi destination.txt
```
8. Navigate to the location in the destination file where you want to paste the copied lines.
10. Paste the copied lines by pressing `Ctrl-Shift-V` (or `Ctrl-V` in some terminals) or `Shift-Insert`.
```
:wq
```
These methods should cover a range of scenarios for selecting and copying lines from one file to
another in Linux. Choose the method that best suits your needs and preferences.
To create a new user account, you can use the `useradd` command. For example:
```
```
```
```
You can use the `usermod` command to modify various properties of a user account. For example,
to change the username:
```
```
```
```
This command will remove the user's home directory and mail spool, but it won't remove any files
owned by the user in other locations.
Users can be part of multiple user groups. You can create and manage groups using the `groupadd`,
`groupmod`, and `groupdel` commands.
To view user account information, including group memberships and home directory, you can use
the `id` and `finger` commands:
```
id username
finger username
```
Users can change their own passwords using the `passwd` command without the need for `sudo`:
```
passwd
```
To lock a user account (prevent login), use the `passwd` command with the `-l` option:
```
```
```
```
9. **Account Expiry**:
You can set an account expiration date for a user with the `chage` command:
```
```
Manage user privileges and permissions using the `sudoers` file, usually edited with the `visudo`
command. This file controls who can execute administrative commands with `sudo`.
Use tools like `auditd` and system logs to monitor user activities and maintain security.
12. **User Account Security**:
Implement best practices for user account security, such as strong password policies, regular
audits, and proper access controls.
Periodically review and remove unused or unnecessary user accounts to enhance system security.
14. **Backups**: Regularly back up user data and configurations to prevent data loss in case of
account issues or system failures.
Some Linux distributions provide graphical user interface tools for user account management,
making it easier for administrators who prefer a graphical interface.
changing password
You can change a user's password in Linux using the `passwd` command. Here's how to do it:
```
passwd
```
3. You will be prompted to enter the current password of the user account you want to change the
password for. After entering the current password, press Enter.
4. If the current password is correct, you will be prompted to enter a new password. Follow these
guidelines when creating a new password:
- The password should be at least 8 characters long (or as per your system's password policy).
- Use a combination of uppercase letters, lowercase letters, numbers, and special characters for a
strong password.
- Avoid using easily guessable information like common words or phrases.
5. After entering the new password, press Enter. You'll be asked to re-enter the new password for
confirmation. Type the new password again and press Enter.
6. If both entries match, you'll see a message indicating that the password has been successfully
updated.
Your user's password is now changed. Keep the new password secure and make sure to remember it,
as it's required for future logins to the user account.
If you have root or superuser privileges (or sudo access), you can also change another user's
password by specifying the username as an argument to the `passwd` command. For example:
```
```
Replace "username" with the actual username of the account you want to change the password for.
This command will prompt you to enter a new password for that user, following the same steps as
described above.
2. **Use the `groupadd` Command**: To create a new group, use the `groupadd` command followed
by the desired group name. For example, to create a group named "mygroup," run the following
command with superuser (root) privileges using `sudo`:
```bash
You will be prompted to enter your password to confirm your administrative privileges.
3. **Verify the Group Creation**: To verify that the group has been created, you can use the `grep`
command to check the `/etc/group` file, which stores group information. Run the following
command to search for your group:
```bash
```
If the group was created successfully, you should see an entry in the `/etc/group` file for
"mygroup."
That's it! You have created a new group in Linux. You can now assign users to this group or configure
permissions for files and directories based on this group.
To add a user to the newly created group, you can use the `usermod` command. For example, to add
a user named "user1" to the "mygroup" group, you can run the following command:
```bash
```
Replace "user1" with the actual username of the user you want to add to the group.
1. **File Permissions**:
File permissions in Linux are represented by three sets of characters: owner, group, and others.
Each set consists of three characters representing read (r), write (w), and execute (x) permissions.
You can set these permissions using the `chmod` command.
- To give read, write, and execute permissions to the owner of a file, use:
```bash
```
```bash
```
```bash
```
You can combine these permission settings as needed. For example, to give read and write
permissions to the owner and read-only permission to the group, you can use:
```bash
```
You can change the ownership of a file or directory using the `chown` command. This is useful
when you want to grant or transfer ownership to a different user.
```bash
chown newowner filename
```
```bash
```
```bash
```
Linux also supports Access Control Lists (ACLs), which provide more fine-grained control over file
and directory permissions. ACLs allow you to specify permissions for multiple users and groups.
- To set an ACL on a file or directory, you can use the `setfacl` command. For example, to grant read
and write access to a specific user on a file:
```bash
```
ACLs are useful when you need to grant permissions to specific users or groups beyond the
standard owner, group, and others.
4. **Using sudo**:
Some system-level operations or modifying system files may require superuser (root) privileges.
You can use the `sudo` command to run commands with elevated privileges, allowing you to change
permissions and access files that are normally restricted.
For example:
```bash
```
Always exercise caution when using `sudo` to avoid unintentional system changes.
**Syntax**:
```bash
```
- `sudo`: You typically need superuser privileges to change file ownership, so use `sudo` to run the
`chown` command with elevated permissions.
- `newgroup`: (Optional) Replace this with the new group's name. If not provided, the group
ownership will remain unchanged.
- `file_or_directory`: Specify the path to the file or directory for which you want to change
ownership.
**Examples**:
1. To change the owner of a file named `example.txt` to the user `newuser`, use:
```bash
2. To change the owner and group of a directory named `mydir` to `user2` and `group2`, respectively,
use:
```bash
```
3. To change the owner of all files and directories within a directory recursively (including
subdirectories), you can use the `-R` option:
```bash
```
1. **File Permissions**:
- **Execute (x)**: Allows running the file if it's a script or executable program.
To set file permissions, you can use the `chmod` command, as described earlier.
2. **Ownership**:
- You can set ACLs using the `setfacl` command, but ensure that your file system supports ACLs
(`getfacl` command can check this).
4. **Secure Filesystem**:
- Utilize secure filesystems like ext4, which offer features like journaling and data integrity checks.
5. **Encryption**:
- Encrypt sensitive files and directories using tools like GnuPG (for individual files) or LUKS (for
entire partitions).
- Use encrypted connections (SSH, HTTPS, etc.) for transferring sensitive data.
6. **File Attributes**:
- Use immutable or append-only file attributes to prevent accidental or intentional changes to files.
- Configure network services to minimize security risks, such as disabling unnecessary services.
- Practice the principle of least privilege. Assign only necessary permissions to users and groups.
- Download software and files from trusted sources to avoid malicious code.
- Verify digital signatures when downloading files, especially if they contain sensitive data.
- Be aware of the permissions mask (umask) that affects default permissions when creating new
files or directories.
1. Open a terminal.
2. Use the following command, replacing `filename` with the name of the file you want to make
readonly:
```bash
```
This command removes the write permission (`-w`) for all users (`a`) for the specified file,
effectively making it readonly.
Method 2: Using Octal Notation
1. Open a terminal.
2. Use the following command to view the current permissions of the file:
```bash
ls -l filename
```
This will display information about the file, including its permissions.
3. Identify the permission string in the output. It will look something like this:
```bash
-rw-r--r--
```
The first character (`-`) represents the file type, and the next nine characters represent the
permissions for the owner, group, and others.
4. To make the file readonly, you need to change the permissions to something like:
```bash
-r--r--r--
```
You can do this by using the `chmod` command with octal notation. In this case, the octal value for
`r--r--r--` is `444`.
```bash
1. **free** Command:
The `free` command is a simple command-line tool that provides information about the system's
memory usage. When you run the `free` command without any arguments, it displays memory
statistics in kilobytes.
```bash
free
```
The output typically includes information about total memory, used memory, free memory, shared
memory, and memory used for buffers and cache. Here's an example of what the output might look
like:
```bash
```
2. **top** Utility:
The `top` utility is an interactive command-line tool that provides real-time information about
system resource usage, including CPU, memory, and more. It continuously updates the display,
making it useful for monitoring system performance over time.
```bash
top
```
The `top` utility displays a dynamic list of processes with information about CPU usage, memory
usage, process ID (PID), user, and more. It also provides summary information about the system's
overall resource usage at the top of the screen.
You can navigate through the `top` interface using various keyboard shortcuts. Some common
shortcuts include:
- Press `1` (the number one) to show individual CPU core usage.
- Press `k` to kill a process (you'll be prompted to enter the PID of the process you want to
terminate).
`top` is a powerful tool for monitoring system performance in real-time and is commonly used by
system administrators and power users to identify resource-hungry processes and troubleshoot
performance issues.
working with processes: types of process,ps Command,Creating
process,killing process
Working with processes in Linux involves various aspects, including understanding types of
processes, using the `ps` command to view process information, creating processes, and terminating
(killing) processes. Let's delve into each of these aspects:
**Types of Processes:**
In Linux, processes can be categorized into several types, primarily based on how they are started
and how they run:
1. **Foreground Processes**: These are processes that run in the foreground and interact directly
with the user through the terminal. They typically block the terminal until they finish executing.
Examples include text editors, command-line utilities, and interactive programs.
2. **Background Processes**: Background processes run independently of the terminal and do not
block user input. You can continue using the terminal while they execute. To start a process in the
background, you can append an ampersand (`&`) to the command, like this:
```
command &
```
3. **Daemons**: Daemons are long-running background processes that perform various system
tasks or services. They are usually started at system boot and run as system services. Examples
include web servers (e.g., Apache), database servers (e.g., MySQL), and print spoolers.
4. **Zombie Processes**: These are processes that have completed their execution but are still listed
in the process table. They exist in this state until their parent process retrieves their exit status.
Zombie processes consume very few system resources.
The `ps` command is used to view information about running processes. It provides various options
to customize the output. Here are some common `ps` commands and options:
- **List all processes for the current user**:
```
ps
```
```
ps aux
```
```
ps --forest
```
```
ps -ejH
```
```
ps -u username
```
```
ps aux --sort=-%cpu,%mem
```
**Creating a Process:**
To create a new process in Linux, you simply run a command in the terminal. For example:
```
firefox
```
**Killing a Process:**
To terminate (kill) a running process in Linux, you can use the `kill` command followed by the
process's PID (Process ID). Here's the basic syntax:
```
kill PID
```
Replace `PID` with the actual Process ID of the process you want to terminate.
You can also use the `pkill` command to terminate processes by their name, or you can use a
combination of commands like `ps` and `grep` to find the PID of a process and then kill it.
```
pkill myprocess
```
Df,du commands
In Linux, the `df` and `du` commands are used to gather information about disk space usage, but they
serve different purposes:
The `df` command is used to display information about the disk space usage on mounted file
systems. It provides a summary of the total disk space, used space, available space, and the
percentage of space used on each mounted file system.
df [options] [filesystem]
```
- `-h`: Display the sizes in human-readable format (e.g., KB, MB, GB).
- `-T`: Display the filesystem type along with the usage information.
- `-a`: Display information about all file systems, including those that are not currently mounted.
Example:
```bash
df -h
```
The `du` command is used to estimate the file and directory space usage on a file system. It
recursively scans directories and reports the disk space used by each file and directory. It helps you
identify which files or directories are consuming the most space.
```bash
du [options] [directories/files]
```
- `-s`: Display only the total size for each specified directory.
- `-c`: Display a grand total at the end (useful when specifying multiple directories).
Example:
```bash
du -sh /path/to/directory
```
This will display the total disk space usage of the specified directory.
In summary, `df` is used to check the disk space usage of mounted file systems, while `du` is used to
analyze the disk space usage of specific directories and files. These commands are essential for
managing and monitoring disk space on a Linux system.
The first step is to identify and remove any unnecessary or large files that you no longer need. You
can use commands like `rm` to delete files and `rmdir` to delete directories.
```
rm filename
```
```
rm -r directoryname
```
2. **Cleaning Package Cache:**
Linux distributions often store package caches, which can consume significant disk space over time.
You can use package managers like `apt` (Debian/Ubuntu), `yum` (Red Hat/CentOS), or `dnf` (Fedora)
to clean package caches:
For APT:
```
```
For YUM:
```
```
If you're running a Linux distribution that receives kernel updates regularly, old kernel versions can
take up a substantial amount of space. Use package manager commands like `apt autoremove`
(Debian/Ubuntu) or `yum autoremove` (Red Hat/CentOS) to remove old kernels.
If your Linux desktop environment has a trash or recycle bin, empty it to permanently delete files
that you've previously deleted.
Log files can grow over time and consume disk space. You can check for large log files in the
`/var/log` directory and truncate or delete them if necessary. Be cautious when deleting logs, as
some may be important for troubleshooting.
Instead of deleting files, you can compress or archive them to save space. Use tools like `tar` and
`zip` to create compressed archives of files or directories.
```
If you need more space than what's available on your current disk, consider resizing partitions or
adding a new disk to your system. This can be a more advanced operation and may require using
tools like `gparted` or `fdisk` to manage partitions.
Some Linux distributions provide disk cleanup tools that can help automate the process of
removing unnecessary files and optimizing disk space usage. For instance, Ubuntu has the "Disk
Usage Analyzer" utility.
You can use filesystem-level compression tools like `zstd` or `gzip` to compress files and directories
to save space. Be aware that this may impact performance for frequently accessed files.
The `find` command is a versatile tool for searching for files based on various criteria. You can use it
to find files that haven't been accessed or modified within a certain timeframe. For example, to find
files that haven't been accessed in the last 90 days:
```
```
To find files that haven't been modified in the last 180 days:
```
```
The `atime` (access time) and `mtime` (modification time) attributes of a file can be used to
determine when it was last accessed or modified. You can use the `stat` command to display this
information for a file:
```
stat filename
```
Some Linux distributions come with a utility called `tmpwatch` that can help locate and remove
unused files. It's often used to clean up temporary directories. To use it, you can specify a directory
and a time threshold to consider files as unused:
```
```
This command will remove files in `/path/to/search` that haven't been modified in the last 7 days.
`rmlint` is a more advanced tool specifically designed for finding and cleaning up duplicate and
unused files. It can perform a deep analysis of your filesystem to identify redundant and unnecessary
files. You can install it from your distribution's package manager.
Usage example:
```
rmlint /path/to/search
```
Some Linux distributions may provide graphical tools to help you identify and manage unused files
and folders. For example, on GNOME-based desktop environments, you can use the "Disk Usage
Analyzer" utility to visualize disk usage and identify large or unused files.
You can use the `date` command to set the system time and date manually. The format for the
command is as follows:
```bash
```
For example, to set the system time to September 12, 2023, 14:30:
```bash
Systemd-based Linux distributions offer the `timedatectl` command to manage system time and date
settings. You can use it to set both the system clock and the hardware clock (RTC). To set the system
clock:
```bash
```
For example, to set the system time to September 12, 2023, 14:30:00:
```bash
```
To ensure accurate timekeeping and synchronization with NTP servers, you can use NTP client
utilities. Most Linux distributions include `systemd-timesyncd`, which is a simple NTP client. To
enable and start it:
```bash
```
This will automatically synchronize your system clock with NTP servers.
After setting the system clock, you can verify the time using the `date` command or `timedatectl` (if
you're using systemd-based systems). Make sure your system's timezone is correctly configured to
ensure accurate time representation.
```bash
date
```
```bash
timedatectl
```
Remember that setting the system time may require superuser privileges (using `sudo`) to ensure
proper system operation and avoid potential issues.
1. **`who`**: The `who` command displays information about currently logged-in users on the
system. It shows details like the username, terminal, login time, and originating IP address (if
applicable).
Example:
```
who
```
2. **`whoami`**: The `whoami` command simply displays the username of the current user.
Example:
```
whoami
```
3. **`finger`**: The `finger` command is used to retrieve information about a user or a list of users
on the system. It can display details such as login name, full name, home directory, and more.
```
finger username
```
4. **`mesg`**: The `mesg` command is used to control whether other users can send messages to
your terminal. It has two options: `y` to allow messages and `n` to disallow messages.
To allow messages:
```
mesg y
```
To disallow messages:
```
mesg n
```
5. **`write`**: The `write` command allows one user to send a message to another user who is
currently logged in and has enabled the `mesg` service. You specify the recipient's username and
terminal.
Example:
```
write username ttyX
```
6. **`wall`**: The `wall` command is used to send a message to all logged-in users. This can be useful
for sending system-wide announcements or alerts.
Example:
```
```
7. **`talk`**: The `talk` command allows two users to have a real-time text-based conversation. It
opens a split-screen window where both users can type and see each other's messages.
```
talk username
```
The `talk` command has become less common in modern Linux distributions, and some systems
may not have it installed by default.
The MOTD is usually stored in a text file. The location of this file may vary depending on your Linux
distribution. Common locations include:
- `/etc/motd`
- `/etc/update-motd.d/`
You can use a text editor like `nano` or `vim` to create or modify the MOTD file. For example, to use
`nano`:
```
```
```
```
In the MOTD file, you can add your custom message, information, or announcements. It's a plain
text file, so you can include any relevant text or ASCII art.
```
```
After adding your message, save the file and exit the text editor.
- In `nano`, press `Ctrl + O` to write changes and `Ctrl + X` to exit.
- In `vim`, press `Esc` to exit insert mode, then type `:wq` and press `Enter` to save and quit.
You can test the MOTD without logging out and back in by using the `cat` command:
```
cat /etc/motd
```
To see the MOTD in action, log out of your Linux system and then log back in. The MOTD will be
displayed before the login prompt.
X windows System
The X Window System, commonly referred to as X or X11, is a graphical windowing system that
provides the foundation for graphical user interfaces (GUIs) in Unix-like operating systems, including
Linux. It allows for the display and management of graphical applications, windows, and user
interfaces on a computer screen. Here are some key points about the X Window System in Linux:
1. **Architecture:** X11 follows a client-server architecture. The X server (or Xorg) is responsible for
managing the hardware display, input devices, and windowing system. Clients (applications) send
requests to the server for drawing graphics and handling user input.
2. **Display Server:** The X server (commonly Xorg) is responsible for controlling the display
hardware, including the monitor and graphics card. It communicates with input devices like
keyboards and mice. Xorg is the most commonly used X server implementation on Linux systems.
3. **Window Managers and Desktop Environments:** X11 itself primarily provides the graphical
infrastructure, and it is complemented by window managers and desktop environments. Window
managers control the placement and appearance of windows, while desktop environments provide a
complete GUI experience, including panels, menus, and system utilities. Common desktop
environments for Linux include GNOME, KDE Plasma, Xfce, and LXQt.
5. **X Protocol:** The X protocol defines how X clients and servers communicate. It specifies
commands for drawing graphics, handling input, and managing windows. This protocol allows for
compatibility across different hardware architectures and operating systems.
6. **X11 Configuration:** Configuration for X11 is typically stored in the `/etc/X11/` directory. The
`xorg.conf` file (or similar configuration files) can be used to specify settings related to the display,
input devices, and drivers.
7. **Display Resolution and Modes:** X11 supports different display resolutions and modes. You can
configure these settings using tools like `xrandr` or through your desktop environment's display
settings.
8. **X11 and Wayland:** While X11 has been the traditional display system on Linux, Wayland is a
newer and more modern display protocol. Some Linux distributions and desktop environments are
transitioning to Wayland as a replacement for X11, as it offers improved security and performance
features. However, X11 remains in use on many systems for compatibility reasons.
9. **Applications:** Most graphical applications on Linux are designed to work with X11. However,
many of these applications can also run on Wayland with the help of compatibility layers.
10. **Customization:** Linux users have a high degree of customization when it comes to their X11-
based desktop environments. They can choose from various window managers, desktop
environments, themes, and icon sets to tailor their graphical experience.