[go: up one dir, main page]

0% found this document useful (0 votes)
17 views16 pages

Notes

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

What Is Linux

Linux is an open-source operating system like other operating systems


such as Microsoft Windows
, Apple Mac OS, iOS, Google android, etc. An operating system is a software that enables the
communication between computer hardware and software. It conveys input to get processed by
the processor and brings output to the hardware to display it. This is the basic function of an
operating system. Although it performs many other important tasks, let's not talk about that.

Linux is around us since the mid-90s. It can be used from wristwatches


to supercomputers. It is everywhere in our phones, laptops, PCs, cars
and even in refrigerators. It is very much famous among developers and
normal computer users.

Evolution of Linux OS
The Linux OS

was developed by Linus Torvalds in 1991, which sprouted as an idea to improve the UNIX
OS. He suggested improvements but was rejected by UNIX designers. Therefore, he thought of
launching an OS, designed in a way that could be modified by its users.

Nowadays, Linux is the fastest-growing OS. It is used from phones to


supercomputers by almost all major hardware devices

Structure Of Linux Operating System


An operating system is a collection of software, each designed for a
specific function.

Linux OS has following components:


1) Kernel
Linux kernel is the core part of the operating system. It establishes
communication between devices and software. Moreover, it manages
system resources. It has four responsibilities:
o device management: A system has many devices connected to it
like CPU, a memory device, sound cards, graphic cards, etc. A
kernel stores all the data related to all the devices in the device
driver (without this kernel won't be able to control the devices).
Thus kernel knows what a device can do and how to manipulate it
to bring out the best performance. It also manages
communication between all the devices. The kernel has certain
rules that have to be followed by all the devices.
o Memory management: Another function that kernel has to
manage is the memory management. The kernel keeps track of
used and unused memory and makes sure that processes
shouldn't manipulate data of each other using virtual memory
addresses.
o Process management: In the process, management kernel
assigns enough time and gives priorities to processes before
handling CPU to other processes. It also deals with security and
ownership information.
o Handling system calls: Handling system calls means a
programmer can write a query or ask the kernel to perform a task.

2) System Libraries
System libraries are special programs that help in accessing the kernel's features. A kernel has to
be triggered to perform a task, and this triggering is done by the applications. But applications
must know how to place a system call because each kernel has a different set of system calls.
Programmers have developed a standard library of procedures to communicate with the kernel.
Each operating system supports these standards, and then these are transferred to system calls for
that operating system.

The most well-known system library for Linux is Glibc (GNU C library).

3) System Tools
Linux OS has a set of utility tools, which are usually simple commands. It is a software which
GNU project has written and publish under their open source license so that software is freely
available to everyone.

With the help of commands, you can access your files, edit and manipulate data in your
directories or files, change the location of files, or anything.

4) Development Tools
With the above three components, your OS is running and working.
But to update your system, you have additional tools and libraries.
These additional tools and libraries are written by the programmers
and are called toolchain. A toolchain is a vital development tool used
by the developers to produce a working application.
5) End User Tools
These end tools make a system unique for a user. End tools are not
required for the operating system but are necessary for a user.

Some examples of end tools are graphic design tools, office suites,
browsers, multimedia players,

What is Bash?

BASH is an acronym for Bourne Again Shell, a punning name, which is a tribute to Bourne
Shell (i.e., invented by Steven Bourne).

Bash is a shell program written by Brian Fox as an upgraded version of Bourne Shell
program 'sh'. It is an open source GNU project. It was released in 1989 as one of the most
popular shell distribution of GNU/Linux operating systems. It provides functional
improvements over Bourne Shell for both programming and interactive uses. It includes
command line editing, key bindings, command history with unlimited size, etc.

In basic terms, Bash is a command line interpreter that typically runs in a text window
where user can interpret commands to carry out various actions. The combination of these
commands as a series within a file is known as a Shell Script. Bash can read and execute
the commands from a Shell Script.

Bash is the default login shell for most Linux distributions and Apple's mac OS. It is also
accessible for Windows 10 with a version and default user shell in Solaris 11.

Command shortcuts
similar in other shells, but be aware there could be subtle
differences.
1. Tab
Tab is my ultimate friend - it never lets me down. It is the
handiest shortcut and time saver ever developed. It
autocompletes commands, file names, or directory names for
you. Simply start typing a command, file name, or directory
name, and then press the Tab key. The system will either
complete the string or display all available options to you.
2. Ctrl+C
Ctrl+C is a well-known shortcut that I use all the time. It
cleanly aborts most programs by sending the SIGINT signal to
the program that I want to interrupt and abort. Most programs
correctly catch it and exit cleanly. If the program does not
specify how to handle SIGINT, the underlying processes are
then self-terminated. Yes, it's safe to use.
3. Ctrl+R/O/G
I find this combination (reverse-i-search) very useful when
searching through my command history. I can bring up
commands that I used previously, navigate through them, and
repeat the command I need. This is very helpful with long and
chained commands.
• Ctrl+R: Recall the last command matching the characters
you provide.
• Ctrl+R (again): Navigate through the matching
commands.
• Ctrl+O: Send the command back to your terminal or
select Enter to execute the command from the search
mode.
• Ctrl+G: Leave the history search mode without running a
command.
4. Ctrl+L
This shortcut is equivalent to the clear command. It clears
your terminal screen.
5. Ctrl+D
This shortcut will effectively log you out of any terminal and
close it, or get you back to the original user when used
after su or sudo commands. It sends an EOF (End-of-file)
marker to bash. Bash exits when it receives this marker. This
shortcut is similar to running the exit command.
6. Ctrl+Alt+D
This shortcut will minimize all terminals/windows and show
your desktop. Repeat it to revert your windows back in the
same order.
7. Ctrl+U
This shortcut erases everything from the current cursor
position to the beginning of the line. I find this useful when I
mistype a command or see a syntax error and prefer to start
over. It's a very handy shortcut.
8. Ctrl+Z
This shortcut is useful if you need to get the terminal back
while working on something. It sends the SIGTSTP signal to
the foreground process. For example, you are working in a
text editor and need to break out to find some data. You can
use this shortcut to suspend and send the editor to the
background, do your other task, and then run fg to get back
into your application.
9. Ctrl+A
Move the cursor to the beginning of the line. Very handy when
you need that little flag added to the beginning of your 200
characters chained-command. I use this instead of the arrow
keys to save time.
10. Ctrl+E
This shortcut does the opposite of Ctrl+A. It moves the cursor
to the end of the line. I always use the Ctrl+A and Ctrl+E
shortcuts to quickly move my cursor around the current line
while typing long or chained commands.

Linux File Hierarchy Structure


• Difficulty Level : Medium
• Last Updated : 12 Dec, 2021
The Linux File Hierarchy Structure or the Filesystem Hierarchy
Standard (FHS) defines the directory structure and directory contents in
Unix-like operating systems. It is maintained by the Linux Foundation.
• In the FHS, all files and directories appear under the root directory /,
even if they are stored on different physical or virtual devices.
• Some of these directories only exist on a particular system if certain
subsystems, such as the X Window System, are installed.
• Most of these directories exist in all UNIX operating systems and are
generally used in much the same way; however, the descriptions here
are those used specifically for the FHS and are not considered
authoritative for platforms other than Linux.
1. / (Root): Primary hierarchy root and root directory of the entire file
system hierarchy.
1. / (Root): Primary hierarchy root and root directory of the
entire file system hierarchy.

• Every single file and directory starts 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


• Example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-
generic

4. /dev : Essential device files, e.g., /dev/null.

• These include terminal devices, usb, or any device attached


to the system.
• Example: /dev/tty1, /dev/usbmon0
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.
• Example: /etc/resolv.conf, /etc/logrotate.conf.
6. /home : Users’ home directories, containing saved files,
personal settings, etc.
• Home directories for all users to store their personal files.
• example: /home/kishlay, /home/kv

7. /lib : Libraries essential for the binaries in /bin/ and /sbin/.


• Library filenames are either ld* or lib*.so.*
• Example: ld-2.11.1.so, libncurses.so.5.7
8. /media : Mount points for removable media such as CD-
ROMs (appeared in FHS-2.3).
• Temporary mount directory for removable devices.
• Examples, /media/cdrom for CD-ROM; /media/floppy for
floppy drives; /media/cdrecorder for CD writer
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. /sbin : Essential system binaries, e.g., fsck, init, route.
• Just like /bin, /sbin also contains binary executables.
• The linux commands located under this directory are used
typically by system administrator, for system maintenance
purpose.
• Example: iptables, reboot, fdisk, ifconfig, swapon

12. /srv : Site-specific data served by this system, such as data


and scripts for web servers, data offered by FTP servers, and
repositories for version control systems.
• srv stands for service.
• Contains server specific services related data.
• Example, /srv/cvs contains CVS related data.
13. /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 system is
rebooted.
14. /usr : Secondary hierarchy for read-only user data; contains
the majority of (multi-)user utilities and applications.

• Contains binaries, libraries, documentation, and source-code


for second level programs.
• /usr/bin contains binary files for user programs. If you can’t
find a user binary under /bin, look under /usr/bin. For
example: at, awk, cc, less, scp
• /usr/sbin contains binary files for system administrators. If
you can’t find a system binary under /sbin, look under
/usr/sbin. For example: atd, cron, sshd, useradd, userdel
• /usr/lib contains libraries for /usr/bin and /usr/sbin
• /usr/local contains users programs that you install from
source. For example, when you install apache from source, it
goes under /usr/local/apache2
• /usr/src holds the Linux kernel sources, header-files and
documentation.
15. /proc : Virtual filesystem providing process and kernel
information as files. In Linux, corresponds to a procfs mount.
Generally automatically generated and populated by the system,
on the fly.
• Contains information about system process.
• This is a pseudo filesystem contains information about
running process. For example: /proc/{pid} directory contains
information about the process with that particular pid.
• This is a virtual filesystem with text information about system
resources. For example: /proc/uptime
File Management in Linux
• Difficulty Level : Easy
• Last Updated : 24 Feb, 2020

In Linux, most of the operations are performed on files. And to handle


these files Linux has directories also known as folders which are
maintained in a tree-like structure. Though, these directories are also a
type of file themselves. Linux has 3 types of files:
1. Regular Files: It is the common file type in Linux. it includes files
like – text files, images, binary files, etc. Such files can be created
using the touch command. They consist of the majority of files in the
Linux/UNIX system. The regular file contains ASCII or Human
Readable text, executable program binaries, program data and much
more.
2. Directories: Windows call these directories as folders. These are the
files that store the list of file names and the related information. The
root directory(/) is the base of the system, /home/ is the default
location for user’s home directories, /bin for Essential User Binaries,
/boot – Static Boot Files, etc. We could create new directories
with mkdir command.
3. Special Files: Represents a real physical device such as a printer
which is used for IO operations. Device or special files are used for
device Input/Output(I/O) on UNIX and Linux systems. You can see
them in a file system like an ordinary directory or file.
In Unix systems, there are two types of special files for each device, i.e.
character special files and block special files. For more details, read the
article Unix file system.

1. Files Listing

To perform Files listings or to list files and directories ls command is


used
$ls
All your files and directories in the current directory would be listed and
each type of file would be displayed with a different color. Like in the
output directories are displayed with dark blue color.
$ls -l

It returns the detailed listing of the files and directories in the current
directory. The command gives os the owner of the file and even which
file could be managed by which user or group and which user/group has
the right to access or execute which file.

2. Creating Files

touch command can be used to create a new file. It will create and open
a new blank file if the file with a filename does not exist. And in case the
file already exists then the file will not be affected.
$touch filename
3. Displaying File Contents

cat command can be used to display the contents of a file. This


command will display the contents of the ‘filename’ file. And if the
output is very large then we could use more or less to fit the output on
the terminal screen otherwise the content of the whole file is displayed at
once.
$cat filename

4. Copying a File

cp command could be used to create the copy of a file. It will create the
new file in destination with the same name and content as that of the file
‘filename’.
$cp source/filename destination/

5. Moving a File
mv command could be used to move a file from source to destination. It
will remove the file filename from the source folder and would be
creating a file with the same name and content in the destination folder.
$mv source/filename destination/

6. Renaming a File

mv command could be used to rename a file. It will rename the filename


to new_filename or in other words, it will remove the filename file and
would be creating a new file with the new_filename with the same
content and name as that of the filename file.
$mv filename new_filename

7. Deleting a File

rm command could be used to delete a file. It will remove the filename


file from the directory.

$rm filename

You might also like