Linux Mynotes2024

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Introduction to Linux

What is Linux?
Linux
Linux is, in simplest terms, an operating system, assembled under the
model of free and open source software development and distribution.

Operating System
Operating systems are computer programs. An operating system is the
first piece of software that the computer executes when you turn the
machine on. The operating system loads itself into memory and begins
managing the resources available on the computer. It then provides those
resources to other applications that the user wants to execute.

To say that Linux is an operating system means that it's meant to be used
as an alternative to other operating systems, Windows, Mac OS, MS-
DOS, Solaris and others. Linux is not a program like a word processor and
is not a set of programs like an office suite. Linux is an interface between
computer/server hardware, and the programs which run on it.

Why Linux?
Linux has proven to be a tremendously stable and versatile operating
system, particularly as a network server. Its down-time is almost
negligible. We can run Linux servers continuously without reboot for many
years. There have been cases when Linux servers have been running for
more than 3-4 years without re-booting and then only taken down for a
brief period for routine maintenance.

History of Linux

Linux began in 1991 as a personal project by Finnish student Linus


Torvalds to create a new free operating system kernel. The resulting Linux
kernel has been marked by constant growth throughout its history.

In 1991, while studying computer science at University of Helsinki, Linus


Torvalds began a project that later became the Linux kernel. He wrote the
program specifically for the hardware he was using and independent of an
operating system because he wanted to use the functions of his new PC
with an 80386 processor. Development was done on MINIX using the GNU
C Compiler.

Linus Torvalds in 2002

Linux is an open-source operating system that powers millions of devices


around the world, from servers and desktop computers to smartphones,
routers, and even embedded systems. It’s based on the Linux kernel,
which was initially created by Linus Torvalds in 1991. Since then, Linux has
grown into a family of operating systems, collectively referred to as Linux
distributions , each tailored for different use cases.

Key Characteristics of Linux:

1. Open Source:
o Freedom and Customization: Linux is free and open-source
software, meaning anyone can access the source code, modify
it, and distribute their own versions. This allows users and
organizations to tailor Linux to their specific needs.
2. The Linux Kernel:
o The kernel is the core of the operating system. It manages
hardware resources (CPU, memory, and devices), provides
process management, and facilitates communication between
software and hardware.
3. Linux Distributions:
o A distribution is a package of the Linux kernel along with
various software tools, libraries, and user interfaces. Popular.
Linux is the most popular operating system which provides several
powerful administrative tools and utilities that help us to manage the
systems effectively. With the Linux command line feature we can access
any system remotely and securely.

Linux OS has many distributor. Some are the following.

Ubuntu:
Currently the most popular distributor. The most user-friendly version for Linux newbies.

Fedora:
The next most popular distributor is Red Hat's free distributor that includes a powerful
desktop GUI based on Gnome 3 but there are also various spins of it that use different
desktops - such as KDE, LXDE, XFCE. It is often amongst the first to include new
technology and is strong on security. It has strong command line feature and is more reliable
and ideally suited to the slightly more adventurous user.

Linux Mint:
It is another user friendly version of Linux, based on the Ubuntu core or can described as "an
improved Ubuntu".

CentOS:
It is completely based on Red Hat Enterprise Linux. It is mostly used for servers.
Red Hat:
It is the best server distribution. But it is not free; you have to pay for it. If an organization
doesn’t mind spending dollars on purchasing the red-hat support, this is no 1 recommendation
to any organization who runs mission critical applications.

Debian:
Debian is known as one of the most well-tested and bug-free distributor. It serves as the
foundation for Ubuntu, most view Debian as a distro best-suited for those experienced with
Linux. Debian has a relatively slow release cycle, with stable ones coming out every one to
three years.

4. Command Line Interface (CLI):


o While many Linux distributions provide graphical user
interfaces (GUIs), Linux is highly powerful when used through
its command-line interface (CLI). The CLI allows users to
perform a wide range of tasks such as file management, system
administration, and software development with precision and
flexibility.
5. Multi-User and Multi-Tasking:
o Linux is designed to be a multi-user operating system,
meaning multiple users can access and use the system
simultaneously. It also supports multi-tasking, enabling
several programs to run at the same time.
6. Security:
o Linux is known for being secure. It has a strong security model,
frequent updates, and the open-source community constantly
audits and patches vulnerabilities. Linux also provides
advanced user permissions and access controls, making it
difficult for unauthorized users to exploit the system.
7. Flexibility and Performance:
o Linux can be used on a wide range of devices, from
supercomputers to tiny embedded systems. Its performance is
highly optimized, making it a preferred choice for tasks
requiring high computing power and low latency (e.g., servers,
scientific computing, and real-time systems).

Common Uses of Linux:

1. Servers: Linux powers the majority of web servers, database servers,


and cloud infrastructure due to its reliability, security, and scalability.
2. Desktop Computers: Many users choose Linux desktops (such as
Ubuntu or Mint) for personal computing. It is free, secure, and
lightweight, making it ideal for older hardware or privacy-conscious
users.
3. Cloud and Virtualization: Linux is widely used in cloud platforms
and for virtualization technologies, like Docker and Kubernetes,
which allow for efficient and scalable application deployment.
4. Development: Developers prefer Linux for its rich set of
programming tools, package managers, and open-source libraries.
5. Embedded Systems: Linux powers devices like routers, smart TVs,
automotive systems, and industrial control systems due to its
lightweight nature and ability to run on a wide variety of hardware.
6. Mobile: Android, the world’s most popular mobile operating system,
is based on the Linux kernel.
Summary:

Linux is a powerful, secure, and highly customizable operating system that


serves a broad range of applications from personal computing to
enterprise-level systems and devices. Its open-source nature ensures
constant innovation, making it a foundational technology across many
industries.

Architecture of linux operating system


Components of Linux:
Like any operating system, Linux consists of software, computer
programs, documentation, and hardware.
The main components of Linux operating system are: Application,
Shell, Kernel, Hardware, Utilities

Linux operating system architecture

1. Hardware: The lowest level of the Linux architecture is the hardware


layer. This layer comprises the physical components of a computer, such as
the hard drive, RAM, motherboard, CPU, network interfaces, and
peripherals. These components are the tangible pieces of your system on
which the rest of the architecture is built.

2. Kernel: Directly interfacing with the hardware layer is the kernel, the
heart of the Linux operating system. As the core part of the OS, the kernel is
responsible for low-level tasks such as disk management, task scheduling,
memory management, and controlling peripherals.

3. Shell: One layer up from the kernel is the shell. In simplest terms, the
shell is a user interface that allows users to interact with the kernel. In
Linux, most interactions with the shell occur in a command-line interface
(CLI), where users type commands interpreted by the shell.

There are several different shells available in Linux, each with its unique
features and syntax, such as
1. The Bourne Shell (sh)
2. Bash (Bourne Again Shell)
3. C Shell (csh)
4. TC Shell (tcsh)
5. Korn Shell (ksh)

4. Applications: The topmost layer of the Linux architecture consists of


applications. These are the software programs that you, as the user, interact
with directly. They range from system applications like file managers, text
editors, and network managers, to user applications like browsers.
While applications communicate with the hardware through the kernel,
they interact with the user through the shell. For instance, when you run a
command to open a file in a text editor, the shell interprets your command,
the kernel fetches the file from the hardware, and the text editor
(application) displays it.
In Linux/Unix operating system everything is a file even directories are files,
files are files, and devices like mouse, keyboard, printer, etc are also files.
Here we are going to see the Directory Structure in Linux.
Types of files in the Linux system.
1. General Files – It is also called ordinary files. It may be an image, video,
program, or simple text file. These types of files can be in ASCII or Binary
format. It is the most commonly used file in the Linux system.
2. Directory Files – These types of files are a warehouse for other file types.
It may be a directory file within a directory (subdirectory).
3. Device Files – In a Windows-like operating system, devices like CD-ROM,
and hard drives are represented as drive letters like F: G: H whereas in
the Linux system devices are represented as files. As for example,
/dev/sda1, /dev/sda2, and so on.

We know that in a Windows-like operating system, files are stored in


different folders on different data drives like C: D: E: whereas in the
Linux/Unix operating system files are stored in a tree-like structure starting
with the root directory as shown in the below diagram.

data storage in Linux/Unix operating systems

The Linux/Unix file system hierarchy base begins at the root and everything
starts with the root directory.
Linux File system/File Hierarchy Standard (FHS)

The Linux File Hierarchy Structure or the File system Hierarchy Standard
(FHS) defines the directory structure and directory contents in Unix-like
operating systems. It is maintained by the Linux Foundation.
These are the common top-level directories associated with the root
directory:
Directories Description

/bin binary or executable programs.

/etc system configuration files.

home directory. It is the default current


/home directory.

/opt optional or third-party software.

/tmp temporary space, typically cleared on reboot.

/usr User related programs.

/var log files.

Some other directories in the Linux system:

Directories Description

It contains all the boot-related information files and folders such as


/boot conf, grub, etc.

/dev It is the location of the device files such as dev/sda1, dev/sda2, etc.
Directories Description

/lib It contains kernel modules and a shared library.

/lost+found It is used to find recovered bits of corrupted files.

It contains subdirectories where removal media devices are


/media inserted.

It contains temporary mount directories for mounting the file


/mnt system.

It is a virtual and pseudo-file system to contains info about the


/proc running processes with a specific process ID or PID.

/run It stores volatile runtime data.

/sbin binary executable programs for an administrator.

/srv It contains server-specific and server-related files.

It is a virtual file system for modern Linux distributions to store and


/sys allows modification of the devices connected to the system.

1. / (Root):
Primary hierarchy root and root directory of the entire file system
hierarchy.
 Every single file and directory start from the root directory.
 The only root user has the right to write under this directory.
 /root is the root user’s home directory, which is not the same as /
2. /bin :
Essential command binaries that need to be available in single-user mode;
for all users, e.g., cat, ls, cp.
 Contains binary executables.
 Common linux commands you need to use in single-user modes are
located under this directory.
 Commands used by all the users of the system are located here e.g. ps,
ls, ping, grep, cp

3. /boot :
Boot loader files, e.g., kernels, initrd.

 Kernel initrd, vmlinux, grub files are located under /boot

4. /dev :
Essential device files, e.g., /dev/null.
 These include terminal devices, usb, or any device attached to the
system.
5. /etc :
Host-specific system-wide configuration files.
 Contains configuration files required by all programs.
 This also contains startup and shutdown shell scripts used to
start/stop individual programs.
6. /home :
Users’ home directories, containing saved files, personal settings, etc.
 Home directories for all users to store their personal files.

7. /lib:
Libraries essential for the binaries in /bin/ and /sbin/.
 Library filenames are either ld* or lib*.so.*
8. /media:
Mount points for removable media such as CD-ROMs
 Temporary mount directory for removable devices.
 Examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives

9. /mnt :
Temporarily mounted filesystems.
 Temporary mount directory where sysadmins can mount filesystems.

10. /opt :
Optional application software packages.
 Contains add-on applications from individual vendors.
 Add-on applications should be installed under either /opt/ or /opt/
sub-directory.

11. /tmp :
Temporary files. Often not preserved between system reboots and may be
severely size restricted.
 Directory that contains temporary files created by system and users.
 Files under this directory are deleted when the system is rebooted.
12. /usr :
Secondary hierarchy for read-only user data; contains the majority of
(multi-)user utilities and applications.

13. /proc:
Virtual filesystem providing process and kernel information as files. In
Linux, it corresponds to a procs mount. Generally, automatically
generated and populated by the system, on the fly.
 Contains information about system process.

Difference between Unix and Linux:


 Unix is a commercial, proprietary operating system originally
designed in the 1970s, used mainly for enterprise servers and
workstations.
 Linux is an open-source, Unix-like operating system kernel that has
evolved into a family of free operating systems (GNU/Linux), used in
everything from personal computers and servers to embedded
systems and mobile devices.

 Unix: Unix systems are typically proprietary and require users to


purchase licenses for enterprise use (especially for commercial Unix
variants).
 Linux: Free to use, though certain enterprise Linux distributions
(like Red Hat Enterprise Linux or SUSE Linux Enterprise) offer
paid support options.
Absolute Path Vs Relative Path In Linux
Absolute Path Vs Relative Path In Linux:
Absolute Path: An absolute path is defined as specifying the location of a file or
directory from the root directory(/). In other words we can say absolute path is a
complete path from start of actual filesystem from / directory.
example:
/home/user/Document/srv.txt

Relative Path: Relative path is defined as path related to the present working
directory(pwd). Suppose I am located in /home/user1 and I want to change directory to
/home/user1/Documents. I can use relative path concept to change directory to
Documents.
example:
here are two examples for changing directory, 1st by using relative path, 2nd by using
absolute path.

$ pwd
/home/user1
$cd Documents/ (using relative path)
$pwd
/home/user1/Documents

Proprietary refers to something that is owned by an individual or a company and is


subject to specific legal rights or restrictions. In the context of technology, software,
hardware, or products that are proprietary are typically closed-source and controlled
exclusively by the owner or creator. Users or consumers must adhere to certain
conditions or licenses to use, modify, or distribute them.

Key Features of Proprietary Software or Technology:

 Ownership:

 Proprietary software or technology is owned by a specific company, developer, or


individual. The source code or inner workings are not publicly available.

 Closed Source:

 Proprietary software is typically closed-source, meaning the source code is not


accessible to the public. Users cannot modify or inspect the underlying code.

 Licensing:

 Users of proprietary software must agree to the license terms set by the owner, which
typically restrict how the software can be used, modified, or redistributed. A common
example is end-user license agreements (EULAs).
 License fees may apply, and the software might come with restrictions on the number
of installations or the types of devices it can be used on.

 Limited Modification:

 Users are generally not allowed to modify proprietary software. Only the owner or
authorized developers can make changes or updates.

 Support:

 Proprietary software often comes with vendor-provided support or updates, usually


at a cost or as part of a licensing agreement.

 Distribution Control:

 The owner of the proprietary software controls how it is distributed and can limit its
availability, restricting users from sharing the software with others.

Examples of Proprietary Software:

 Microsoft Windows: A proprietary operating system developed by Microsoft. Users


need to purchase a license to use it, and the source code is not available for
modification.
 Adobe Photoshop: A proprietary image-editing software that requires users to
purchase or subscribe to it. The source code is closed, and users can't modify or
redistribute the software.
 MacOS: Apple's proprietary operating system, which is only licensed for use on
Apple hardware.

Most commonly Used Text Editors in Linux


For Linux users, text editors are essential tools that play a crucial role in various tasks,
from coding and writing to system administration and configuration management.
Linux offers a wide range of text editors, catering to different preferences and use
cases. In this article, we will delve into the world of Linux text editors, exploring their
features, strengths, and popular choices among the community.
Mostly Used Text Editors in Linux
 Vi Text Editor
 Vim Editor
 Nano Editor
 Atom Editor
 Emacs Editor

The Linux shell is the bridge that connects the user with the operating system. At the
core of the Linux operating system lies the kernel. This kernel is responsible for
managing the resources of the computer, like the memory, CPU, etc. When the user
wants to make the kernel work, it has to connect to it through a shell. Linux shell
programming is the term associated with shell scripting, which uses simple English to
give instructions to the computer. You can even instruct the operating system to do
repetitive tasks through Linux shell programming.

Note:
*System hard disk is named as cygdrive

*All the drives of my windows OS will be present under/cygdrive

*All directories (folders) are accessed using '/'(delimiter) separation

*In Linux 'Tab'key play an important roll

*tab button on keyboard is used to automatically fill the paths and names

*bash:bourne again shell

*pwd:present working directory

cd: change directory

cd /:root directory

cd ~:Home directory

cd .. goes to previous directory

cd ../../../ goes to previous directories(3 steps previous)

cd path1/path2/path3/: Absolute Path

cd 'dir name' :if directory name is 'my name'

cd "dir name" :if directory name is "my name"

cd dir\ name :if directory name is my\ name

clear:it clear the terminal screen

ls:list the directory and files

ls /:list of root directory contents

ls ~:list of home directory contents

ls dir_name: list of "dir_name" contents

ls .. list the contents of previous directory

ls -l:long listing format

ls -a: list the hidden file and directories (list all files and directories)

ls -la: long list with hidden directories


ls -sl list the contents according to size

ls -t : sort by time, newest first;

ls -r : reverse order while sorting

ls -ltr:long list with time and reverse sorting

ls -d */:list of only directories

man <command>:manual of given command

q: to exit from manual

File management

---------------

command used to create files are

*touch

*cat

touch <filename1.ext> <filename2.ext>

touch filename{1..10}.txt

touch directory/filename --> this command create a file in a directory directly

this command creates the file

cat: its echoes what you typed

*cat: concatenate files and print on the standard output

cat file_name:display the contents of the file

cat dir1/filename

cat -b filename : add the line numbers to non-blank lines

cat -n filename : add the line numbers to all lines

cat > filename : '>' this redirects and open the file for edit

cat >> filename : '>>' this appends and edit without overwriting the previous data of file

cat file1 > file2 this command redirect the contents file1 to file2

cat dir1/filename display the content of the filename.


To create different type extention files with different names

-------------------------------------------------------------

for i in $(seq 1 5)

do

touch file$i.txt File$i.v newfile$i.py Sample$i.c Program$i

done

Make Directories

----------------

mkdir <directory_name>: make directory

mkdir <name1> <name2> <name3>

mkdir <name1>/<name2>

mkdir dir{1..10}

mkdir -p <name1>/{name2,name3,name4}

mkdir -p <name1>/<name2>/<name3>/<name4>

mkdir -pv <name1>/<name2>/<name3>/<name4>

mkdir -p its creates the directories with parent directory with sub directory

mkdir -pv print a message for each created directory

ls -R list out the directory structure

rm & rmdir commands

-------------------

rmdir <dir_name>

rmdir -p <name1>/<name2>/<name3>/<name4>

rmdir -pv <name1>/<name2>/<name3>/<name4>

rm -rv <name1> rv--> means recrussive verbose


copying directories

********************

cp :{souce file/dir to destination file/dir}

cp sum1 sum2; [sum1 is copied to sum2]

cp filename{1..10}.txt directory

cp -r dir1 new_dir {it creates a new_dir and copies the content of dir1}

cp -r dir1 dir3 { if dir3 already exists,it will copy the dir1 to dir3}{

cp -i without overwrite

cp ../test1.txt ../test2.txt . from previous directory it takes the files and copy to current directory [dot
represent current directory]

Move Directories/files

mv source dir1 destination dir2 [dir1 moved to dir2]

mv dir1 ./dir11/dir12/dir13/dir14 {note '.' represent current directory}in this above command dir1
moved to sub directory dir14

mv -i file3.txt dir1

how to rename directories

mv junk junk1 {here the junk directory renamed as junk1} so 'mv' can be used for rename also

mv example /cygdrive/c/Users/VLSIGURU/Desktop/ this command will move directory 'example' to


desktop by the path given my us.

mv filename{1..10}.txt directory

Note: 1.mv command we can move single source_file to single destination_file

2.we can move multiple files to single directory (but the directory should exist)

3.we can move single directory to single directory(its not compulsory that

destination directory should exist)

4.we can move multiple directories to single directories(but destination directory

should exist)

Miscellaneous Commands
----------------------

1. ls : list all the files and directories.

2. pwd : present working directory.

3. head: display the top 10 lines of the file.

4. Tail : Display the bottom 10 lines of the file.

5. Tac : Display the lines in the reverse order.

6. More : Similar to cat command. We can display large content.

7. Less : we can display small content.

8. Id : Display the ID of the user (or) group.

9. Ping : check the network connectivity, status of network/server.

10. Hostname : Display the owner name.

11. Ps : used to list the currently running processes and their PIDs along with some

other information depends on different options.

12. Kill : It is used for manually terminating the processes.

13. who : lets you display the users currently logged in to your UNIX or Linux

operating system.

14. Whoami : It displays the username of the current user when this command is

invoked.

15. Date :displays current date and time

16. Cal : display current year calender

You might also like