Linux
Linux
Linux is an open-source operating system like other operating systems such as Microsoft Window ,Mac OS,
iOS, Google android, etc. An operating system is a software that enables the communication between
computer hardware and software
A. Linux Features
Multitasking: More than one function can be performed simultaneously by dividing the CPU time intelligently.
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.
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).
Open Source: Linux code is freely available to all
File System: Provides hierarchical file system in which files and directories are arranged
C. What is Shell
The terminal contains the shell; it allows us to execute the commands to interact with the system. We can
perform various operations such as store and retrieve data, process information. Some basic operations such
as date, cal, ls, and pwd
D. What is Scripting
Suppose we are required to execute some basic commands every day, for example above four commands.
Linux supports a feature called scripting that allows us to execute more than one task at once. So, it is good to
define a script rather than performing repetitive tasks.
To understand how to use Linux script, let's define a script in a combination of some tasks. To define a script,
create a file with a .sh extension. Consider below command:
Command :- vi tasks.sh
The above command will open the vi editor in normal mode. Switch it to insert mode by pressing ESC, and
after that enter 'i' keys, enter your desired tasks. Every task should be defined in a new line. Consider the
below tasks:
1. date
2. cal
3. pwd
4. ls
After entering the tasks, press ESC and :wq! Keys to save and exit from the editor.Now, make the created file
as executable, use the chmod command with +x option as follows:
chmod +x tasks.sh
We have created our first script. To execute the shell script, execute the file name by predefining './ ' with
the file name. Consider the below command:
./task.sh
Examples It has different distros/Varients like Ubuntu, IBM AIX, HP-UX and Sun Solaris.
Redhat, Fedora, etc
Users Nowadays, Linux is in great demand. Anyone can It was developed mainly for servers,
use Linux whether a home user, developer or a workstations and mainframes.
student.
Usage Linux is used everywhere from servers, PC, It is used in servers, workstations and
smartphones, tablets to mainframes and PCs.
supercomputers.
Cost Linux is freely distributed, downloaded, and Unix copyright vendors decide
distributed through magazines also. And priced different costs for their respective Unix
distros of Linux are also cheaper than Windows. Operating systems.
Development As it is open source, it is developed by sharing Unix was developed by AT&T Labs,
and collaboration of codes by world-wide various commercial vendors and non-
developers. profit organizations.
Interface The default interface is BASH (Bourne Again It originally used Bourne shell. But is
SHell). But some distros have developed their also compatible with other GUIs.
own interfaces.
File system Linux supports more file system than Unix. It also supports file system but lesser
support than Linux.
Security It provides higher security. Linux has about 60- Unix is also highly secured. It has about
100 viruses listed till date. 85-120 viruses listed till date
F. Linux vs windows
Access Users can access the source code of Usually, users cannot access the source
kernel in Linux and can alter the kernel code.
according to need.
Installation The Linux installation process is a bit Windows OS is easy to install and set
complicated to set up as it requires many up on a machine; it requires fewer user
user inputs. It takes less time than input options during installation.
Windows to install. However, it takes more time to install
as compared to Linux.
Ease of use The Linux OS is meant to be for the Windows comes with simple and rich
technical user because you must have GUI options, so it is easy to use it. It
some exposure to various Linux can be simply used by technical as well
commands. Users may take more time to as non-technical users. The
be a handy user of Linux. The troubleshooting process is also much
troubleshooting process is also easy than Linux.
complicated as compared to Windows.
Reliability Linux is highly reliable and secure. It has Windows is not as much reliable as
well-established system security, process Linux. However, now Windows has
management, and uptime. improved reliability but still has some
security weaknesses and system
instabilities.
Security Linux OS is more secure than Windows. Windows is less secure than Linux.
It is hard for the hackers and attackers to Attackers primarily target the Windows
find a loophole in it. So, Linux is hard to for malware and virus. Windows is
breakthrough. most vulnerable without anti-virus.
G. Linux Distro
Distribution Why To Use
Linux mint It works like windows and should be use by new comers.
CentOS If you want to use red hat but without its trademark.
OpenSUSE It works same as Fedora but slightly older and more stable.
Arch Linux It is not for the beginners because every package has to be installed by yourself.
pwd The pwd command stands for (print working directory). It displays the current working location
or directory of the user. It displays the whole working path starting with /. It is a built-in
command.
ls The ls command is used to show the list of a folder. It will list out all the files in the directed
folder.
cd The cd command stands for (change directory). It is used to change to the directory you want to
work from the present directory.
mkdir With mkdir command you can create your own directory.
mkdir <dirname1> <dirname2> <dirname3> ...
rmdir The rmdir command is used to remove a directory from your system.
This command is used to delete a directory. But will not be able to delete a directory
including a sub-directory. It means, a directory has to be empty to be deleted.
Syntax: rmdir <dirname>
To change the directory by using an absolute path, we have to mention the whole path starting from the root.
Consider the below example:
From the above output, we are changing our directory to 'certs' from 'cups.' So, we have provided the whole
path "/run/cups/certs" starting from the root (/). This is called an absolute path.
1. cd certs
From the above output, we are changing the directory by using a relative path. Like the above example, we
have changed our directory from 'cups' to 'certs,' but have not mentioned the whole path. This is the
relative path.
ls Description
option
ls -a In Linux, hidden files start with . (dot) symbol and they are not visible in the regular directory. The (ls -a)
command will enlist the whole list of the current directory including the hidden files.
ls -lh This command will show you the file sizes in human readable format. Size of the file is very difficult to read
when displayed in terms of byte. The (ls -lh)command will give you the data in terms of Mb, Gb, Tb, etc.
There are multiple ways to create a file in Linux. Some conventional methods are as follows:
Output:
1. cat > test.txt
The above command will create a text file and will enter in the editor mode. Now, enter the desired text and
press CTRL + D key to save and exit the file and it will return to the command line.
To display the content of the file, execute the cat command as follows: cat test.txt
2. Using the touch command It is used to create a new file, update the time stamp on
existing files and directories. It can also create empty files in Linux.
To create a file, execute the touch command followed by the file name as given below:
1. touch test1.txt
To list the information of the created file, execute the below command:
1. ls - l test1.txt
To create multiple files at once, specify files and their extensions after the touch command along with single
space.
1. touch test1.txt test2.txt test3.txt
1. touch test4.txt test.odt
The above command will create two different files named as test4.txt and test.odt.
1. ls -l
Note: The significant difference between touch and cat command is that using cat command, we can specify the
content of the file from the command prompt comparatively the touch command creates a blank file.
To create a file with redirect (>) operator, execute the command as follows: > test5.txt
4.Using Vi editor
To create a file with Vi editor, execute the below command: vi test10.txt
The above command will open the Vi editor. Press i key for the insert mode and enter the file content. Press
Esc key and :wq to save and exit the file from the editor.
Syntax file <filename>
In above snapshot, we have created a copy of 'docu' and named it as 'newdocu'. If in case, (in our case it is
'newdocu') alreade exists, then it will simply over write the earlier file.
L2. cp Options
Option Function
In the example below we have converted all the files ending with '.txt' into files ending with '.pdf'.
But generally [option(s)] are not used. Only keyword is written as an argument.
The 'head' command displays the starting content of a file. By default, it displays starting 10 lines of any file.
If we'll write two file names then it will display first ten lines (in this case file has five lines only) of each file
separated by a heading.
Syntax: tail <file name>
To track a file for changes, the '-f' option is used. Here, '-f' stands for the following. It is useful for monitoring
log files. tail -f num.txt
Q. Linux Cat Command
It can be used to display the content of a file, copy content from one file to another, concatenate the contents
of multiple files, display the line number, display $ at the end of the line, etc.
Syntax: cat <fileName> Note: To display the content of multiple files at once, type file names in one single
line like "cat file1 file2 file3... fileN.
cat [oldfile] > [newfile] To copy content from older to new file.
cat [file1 file2 and so on] > [new file name] To concatenate contents of multiple files into one.
The 'cat' command can be used to create a new file with greater than sign (>).
In the above snapshot, we have created a new file called "javatpoint". Now let's see how to create it.Type the
command "cat >javatpoint" and press 'enter'. You will be directed to the next line.Press 'enter' after every
line and you will be directed to the next line. To save your file, go to the next line, press 'ctrl+d' and your file
will be saved.
Q3. To Append the Content of A File
The 'cat' command with double greater than sign (>>) append (add something in the last of a file) something in
your already existing file.
The 'cat' command can be used to concatenate the contents of multiple files in a single new file.
Syntax: tac <file name>