Linux Fundamentals & Shell Programmin
Linux Fundamentals & Shell Programmin
What is Linux
Linux is a powerful and flexible family of operating systems that are free to use and share. It was
created by a person named Linus Torvalds in 1991. What’s cool is that anyone can see how the
system works because its source code is open for everyone to explore and modify. This openness
encourages people from all over the world to work together and make Linux better and better. Since
its beginning, Linux has grown into a stable and safe system used in many different things, like
computers, smartphones, and big supercomputers. It’s known for being efficient, meaning it can do
a lot of tasks quickly, and it’s also cost-effective, which means it doesn’t cost a lot to use. Lots of
people love Linux, and they’re part of a big community where they share ideas and help each other
out. As technology keeps moving forward, Linux will keep evolving and staying important in the
world of computers.
Linux Distribution
Linux distribution is an operating system that is made up of a collection of software based on Linux
kernel or you can say distribution contains the Linux kernel and supporting libraries and software.
And you can get Linux based operating system by downloading one of the Linux distributions and
these distributions are available for different types of devices like embedded devices, personal
computers, etc. Around 600 + Linux Distributions are available and some of the popular Linux
distributions are:
MX Linux
Manjaro
Linux Mint
elementary
Ubuntu
Debian
Solus
Fedora
openSUSE
Deepin
Architecture of Linux
Kernel: Kernel is the core of the Linux based operating system. It virtualizes the common hardware
resources of the computer to provide each process with its virtual resources. This makes the process
seem as if it is the sole process running on the machine. The kernel is also responsible for preventing
and mitigating conflicts between different processes. Different types of the kernel are:
Monolithic Kernel
Hybrid kernels
Exo kernels
Micro kernels
System Library:Linux uses system libraries, also known as shared libraries, to implement various
functionalities of the operating system. These libraries contain pre-written code that applications
can use to perform specific tasks. By using these libraries, developers can save time and effort, as
they don’t need to write the same code repeatedly. System libraries act as an interface between
applications and the kernel, providing a standardized and efficient way for applications to interact
with the underlying system.
Shell:The shell is the user interface of the Linux Operating System. It allows users to interact with the
system by entering commands, which the shell interprets and executes. The shell serves as a bridge
between the user and the kernel, forwarding the user’s requests to the kernel for processing. It
provides a convenient way for users to perform various tasks, such as running programs, managing
files, and configuring the system.
Hardware Layer: The hardware layer encompasses all the physical components of the computer,
such as RAM (Random Access Memory), HDD (Hard Disk Drive), CPU (Central Processing Unit), and
input/output devices. This layer is responsible for interacting with the Linux Operating System and
providing the necessary resources for the system and applications to function properly. The Linux
kernel and system libraries enable communication and control over these hardware components,
ensuring that they work harmoniously together.
System Utility: System utilities are essential tools and programs provided by the Linux Operating
System to manage and configure various aspects of the system. These utilities perform tasks such as
installing software, configuring network settings, monitoring system performance, managing users
and permissions, and much more. System utilities simplify system administration tasks, making it
easier for users to maintain their Linux systems efficiently.
Advantages of Linux
The main advantage of Linux is it is an open-source operating system. This means the source code is
easily available for everyone and you are allowed to contribute, modify and distribute the code to
anyone without any permissions.
In terms of security, Linux is more secure than any other operating system. It does not mean that
Linux is 100 percent secure, it has some malware for it but is less vulnerable than any other
operating system. So, it does not require any anti-virus software.
Various Linux distributions are available so that you can use them according to your requirements or
according to your taste.
It provides high stability. It rarely slows down or freezes and there is no need to reboot it after a
short time.
The performance of the Linux system is much higher than other operating systems. It allows a large
number of people to work at the same time and it handles them efficiently.
It is network friendly.
The flexibility of Linux is high. There is no need to install a complete Linux suite; you are allowed to
install only the required components.
It is fast and easy to install from the web. It can also install it on any hardware even on your old
computer system.
It performs all tasks properly even if it has limited space on the hard disk.
Disadvantages of Linux
Open Source: Linux is open-source, meaning its source code is freely available for anyone to view,
modify, and distribute. This fosters a collaborative environment and encourages innovation.
Customization: Linux offers a high degree of customization, allowing users to tailor the operating
system to their specific needs. There are numerous distributions (distros) of Linux, each with its own
set of features and configurations.
Stability and Reliability: Linux is known for its stability and reliability, particularly in server
environments. It is often chosen for critical infrastructure due to its robustness and ability to handle
heavy workloads.
Security: Linux is inherently more secure than some other operating systems due to its design
principles and the open-source nature that allows for quick identification and patching of security
vulnerabilities.
Performance: Linux tends to perform well even on older or less powerful hardware, making it
suitable for a wide range of devices, from servers to embedded systems.
Community Support: The Linux community is vast and active, providing extensive documentation,
forums, and support channels for users to seek help and share knowledge.
Cost: Linux is free to use and distribute, which can result in significant cost savings, especially for
organizations deploying it on a large scale.
However, it's essential to note that Linux may not be the best choice for every scenario. Some users
may prefer the familiarity and software compatibility of other operating systems like Windows or
macOS, depending on their specific needs and workflows. Ultimately, the "better" operating system
is subjective and depends on individual requirements and preferences.
Cron Table: The cron command uses a configuration file called the "cron table" or "crontab." Each
user on a Linux system can have their own cron table, which contains entries specifying the
commands or scripts to run and when to run them.
Syntax: The syntax for a cron job entry in the cron table follows a specific format:
markdown
Copy code
* * * * * command_to_run
Minute (0-59)
Hour (0-23)
Month (1-12)
Special Characters: In addition to numeric values, special characters can be used in cron job entries:
, - Allows specifying multiple values within the same parameter (e.g., 1,15,30 for minutes means the
job will run at minute 1, 15, and 30).
- - Specifies a range of values (e.g., 10-15 for hours means the job will run from hour 10 to hour 15,
inclusive).
/ - Allows specifying intervals (e.g., */5 for minutes means the job will run every 5 minutes).
Examples:
To edit the cron table, you can use the crontab -e command, which opens the user's cron table in the
default text editor.
cron is a powerful tool for automating tasks in Linux, providing users with the ability to schedule
routine operations without manual intervention.
n Linux, the batch command is used in conjunction with the kill, sleep, and who commands to
manage processes, delay execution, and display information about users currently logged into the
system. Here's an explanation of each command:
batch Command:
The batch command is used to execute commands when system load levels permit. It is typically
used to schedule commands or scripts to run when the system load average drops below a certain
threshold. This helps prevent unnecessary strain on the system during periods of high activity.
Options:
Example: batch script.sh would schedule the execution of the script script.sh when system load
levels are low.
kill Command:
The kill command is used to terminate or send signals to processes in Linux. It allows users to stop
processes that are running or alter their behavior.
Options:
-9 or SIGKILL: Forces termination of the process by sending the SIGKILL signal, which cannot be
ignored or caught by the process.
Example: kill -9 1234 would forcefully terminate the process with PID 1234.
sleep Command:
The sleep command is used to delay the execution of commands or scripts for a specified amount of
time. It is often used in shell scripts to introduce delays between commands.
Example: sleep 5 would pause execution for 5 seconds before proceeding to the next command.
who Command:
The who command is used to display information about users who are currently logged into the
system. It shows details such as username, terminal, login time, and remote host (if applicable).
Options:
Example: who would display a list of users currently logged into the system.
By using these commands together, users can manage processes, delay execution, and monitor user
activity on a Linux system effectively.
Linux Commands
Linux, often associated with being a complex operating system primarily used by developers, may
not necessarily fit that description entirely. While it can initially appear challenging for beginners,
once you immerse yourself in the Linux world, you may find it difficult to return to your previous
Windows systems. The power of Linux commands in controlling your PC, coupled with their clean
user interface, can make it hard to switch back to older operating systems. If you’re a developer, you
can likely relate to the advantages and appeal of Linux.
To support developers and beginners alike, we have created a comprehensive Linux/Unix command
line cheat sheet. This cheat sheet covers all the basic and advanced commands, including file and
directory commands, file permission commands, file compression and archiving, process
management, system information, networking, and more with proper examples and descriptions. In
addition to that we provide all the most used Linux Shortcut which includes Bash shortcuts, Nano
shortcuts, VI & Vim Shortcuts Commands. It provides a solid foundation on Linux OS commands, as
well as insights into practical applications.
By the end of this cheat sheet, you will have a basic understanding of Linux/Unix Commands and
how it makes development easy for developers.
In this Linux cheat sheet, we will cover all the most important Linux commands, from the basics to
the advanced. We will also provide some tips on how to practice and learn Linux commands. This
cheat sheet is useful for Beginners and Experience professionals.
File and directory operations are fundamental in working with the Linux operating system. Here are
some commonly used File and Directory Operations commands:
ls -l
displays files and directories with
-l: Long format
detailed information.
listing.
ls -a
List files and -a: Include hidden
shows all files and directories,
directories. files hidden ones
including
-h: Human-readable
ls -lh
file sizes.
displays file sizes in a human-
ls readable format.
cd /path/to/directory
Change directory. changes the current directory to
cd the specified path.
pwd
Print current working
displays the current working
directory.
pwd directory.
mkdir my_directory
Create a new
creates a new directory named
directory.
mkdir “my_directory”.
-r: Remove
Remove files and rm file.txt
directories
directories. deletes the file named “file.txt”.
rm recursively.
Command Description Options Examples
rm -f file.txt
forcefully deletes the file “file.txt”
without confirmation.
cp -r directory destination
copies the directory “directory”
and its contents to the specified
Copy files and -r: Copy directories destination.
directories. recursively.
cp file.txt destination
copies the file “file.txt” to the
cp specified destination.
mv file.txt new_name.txt
renames the file “file.txt” to
Move/rename files and “new_name.txt”.
directories. mv file.txt directory
moves the file “file.txt” to the
mv specified directory.
cat file.txt
View the contents of a
displays the contents of the file
file.
cat “file.txt”.
head file.txt
shows the first 10 lines of the file
-n: Specify the “file.txt”.
Display the first few
number of lines to
lines of a file. head -n 5 file.txt
display.
displays the first 5 lines of the file
head “file.txt”.
Command Description Options Examples
tail file.txt
shows the last 10 lines of the file
-n: Specify the “file.txt”.
Display the last few
number of lines to
lines of a file. tail -n 5 file.txt
display.
displays the last 5 lines of the file
tail “file.txt”.
ln -s source_file link_name
Create links between -s: Create symbolic creates a symbolic link named
files. (soft) links. “link_name” pointing to
ln “source_file”.