Linux Level1
Linux Level1
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
1 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
INDEX
Part-1: UNIX/LINUX Concepts & Commands …………………………………………………………………… 4
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
2 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
3 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Part-1
UNIX / LINUX
Concepts
&
Commands
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
4 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Agenda
Topic-1: Overview of UNIX/Linux Operating System
Topic-13: Piping
Topic-18: Compression and Uncompression of files (tar, gzip, gunzip, bzip2, bunzip2)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
5 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-1: Overview of
UNIX/Linux Operating System
What is UNIX?
Flavours of UNIX
Components of UNIX
Online Terminal Demo with some basic commands
What is UNIX?
✽ It is an operating system, by using that, users/applications can communicate with hard
ware components.
✽ It was developed/created in 1960s.
✽ With lot of extensions and improvements to base version, several flavours introduced
by organization/companies (flavours like Redhat linux, ubuntu, CentOS etc)
Features of UNIX:
1) It is FOSS (Freeware and Open Source Software)
2) UNIX can be used by multiple users simultaneously and hence it is Multi User
operating System.
3) Several tasks can be executed simultaneously and hence it is multi tasking operating
system.
4) It is user friendly and provides both CUI and GUI Support.
5) When compared with windows, UNIX is more secured.
Flavours of UNIX:
As UNIX is open source, multiple flavours are available with lot of extensions and
improvements.
Ubuntu
RedHat
Centos
Fedora
Slackware
open solaries
Suse Linux Enterprise server (SLES)
Open Suse
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
6 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
All these flavours have lot of similarity. Hence if we are perfect with one flavour, we can
work on any other flavour very easily.
Components of UNIX
Shell:
✽ It is the outer layer of UNIX operating System.
✽ It reads our command, verify syntax and check whether the corresponding command
related application is available or not.
✽ If everything is proper, then shell interprets our command into kernal understandable
form and handover to the kernal.
✽ Shell acts as interface between user and kernal.
Kernal:
✽ It is the core component of UNIX operating system.
✽ It is responsible to execute our commands.
✽ It is responsible to interact with hardware components.
✽ Memory allocation and processor allocation will takes care by kernal.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
7 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
5) Once command execution completed, then shell returns unix prompt ($ OR # OR %).
6) $ OR # OR % represents it is ready for the next command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
9 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-2: Linux
File System
Types of Files in Linux:
In Linux everything is treated as File.
All files are divided into 3 types
2) Directory Files:
These files represent directories.
In windows, we can use folder terminology where as in linux we can use directory
terminology.
Directory can contains files and sub directories.
3) Device Files:
In Linux, every device is represented as a file. By using this file we can communicate
with that device.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
10 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: c, b, s are representing system files and mostly used by super user (also known as
root user or admin user)
2) $ cd .
Changes to Current Directory (Useless)
3) $ cd ..
Changes to Parent Directory
4) $cd
If we are not passing any argument, then changes to user home directory.
5) $ cd ~
~ Means User Home Directory.
It will Changes to User Home Directory.
6) $ cd -
- Means Previous Working Directory.
It will Changes to Previous Working Directory.
durgasoft@durgasoft:~/Downloads/coreutils-8.31/src$ pwd
/home/durgasoft/Downloads/coreutils-8.31/src
durgasoft@durgasoft:~/Downloads/coreutils-8.31/src$ cd ~
durgasoft@durgasoft:~$ pwd
/home/durgasoft
durgasoft@durgasoft:~$ cd -
/home/durgasoft/Downloads/coreutils-8.31/src
durgasoft@durgasoft:~/Downloads/coreutils-8.31/src$ pwd
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
11 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
/home/durgasoft/Downloads/coreutils-8.31/src
durgasoft@durgasoft:~/Downloads/coreutils-8.31/src$ cd ../../..
durgasoft@durgasoft:~$ pwd
/home/durgasoft
1) bin Directory:
bin means binary. This directory contains all binary executables related to our linux
commands.
2) sbin Directory:
sbin means systembin. It contains all binary executables related to high end admin
(super user OR root) commands.
Eg: Disk partitioning, network management etc
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
12 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
3) etc Directory:
This directory contains all system configuration files. These configurations can be used
to customize behaviour of linux os.
All users information available in /etc/passwd file.
All groups information available in /etc/group file.
Hosts information (ip address and dns names) available in /etc/hosts file.
4) tmp Directory:
tmp means temporary. It contains all temporary files created in the current session.
If any file is required only for the current session, then create that file inside tmp
directory. These files will be deleted automatically at the time of system shutdown.
If any file which is required permanently, then it is not recommended to create inside
tmp directory.
5) dev Directory:
dev means device.
In Linux, everything is treated as a file including devices also. i.e every device is
represented as a file. By using these files, we can communicate with the devices.
All device related files will be stored inside dev directory.
Eg:
tty Terminal related File
fd Floppy Drive related File
hd Hard Disk related File
ram RAM related File
stdin standard Input Device File (keyboard)
stdout Standard Output Device File (Terminal/Monitor)
stderr Standard Error Device File (Terminal/Monitor)
6) mnt Directory:
mnt means mounting.
We have to attach external file system files from Pen drive, CD, external hard disk etc
to the Linux File System. Then only we can use those external files. This attachment
process is called mounting.
In the old operating systems, we have to perform mounting manually. But in recent
operating systems, mounting is performing automatically and we are not required to
perform manually.
The files of manual mounting will be placed inside mnt directory.
7) media Directory:
The files of automatic mounting will be placed inside media directory.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
13 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
8) opt Directory:
opt means optional.
This directory contains all 3rd party software installation files.
Eg:
If we are installing any software explicitly like google chrome, then the corresponding
installation files will be stored inside opt directory.
9) lib Directory:
lib means library. It contains Linux os libraries which are required by our commands
and applications.
Note:
/home/durgasoft Is called durgasoft user home directory. It contains multiple sub
directories like Desktop, Downloads, Movies, Pictures etc.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
14 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:/$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 11:05 ? 00:00:03 /sbin/init
root 2 0 0 11:05 ? 00:00:00 [kthreadd]
root 3 2 0 11:05 ? 00:00:00 [rcu_gp]
root 4 2 0 11:05 ? 00:00:00 [rcu_par_g
....
Note:
/home/durgasoft Durgasoft User Home Directory
/root Super User Home Directory
Note:
1) The main advantage of Linux File System is, operating system can locate required files
very easily.
2) For every File System, a separate name will be assigned.
3) ext2,ext3,ext4,XFS are names of Linux File Systems.
4) NTFS, FAT are names of Windows File Systems.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
15 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-3: Linux
Installation
1) Oracle Virtual Box Installation
2) Virtual Machine Installation with Ubuntu OS
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
16 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Various Utilities:
1) To make Full Screen: Devices Insert Guest Additions CD Image
2) To open terminal: ctrl+alt+t
3) To close terminal: ctrl+d
4) To increase font in terminal: ctrl+shift+plus symbol
5) To decrese font in terminal: ctrl+ minus symbol
6) To copy and paste from windows to ubuntu and from ubuntu to windows:
Devices Shared Clipboard Bidirectional
7) To drag and drop files from windows to ubuntu and from ubuntu to windows:
Devices Drag and Drop Bidirectional
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
17 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
man ls
It provides complete information about ls command.
2) ls -r
It will display all files and directories in reverse of aplhabetical order.
3) ls | more
To display content line by line
(To come out we have to use q)
4) ls | pg
To display content page by page.
Each page contains 20 lines of content.
(To come out we have to use q)
5) ls -l
To display long listing of files
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
18 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
6) ls -t
To display all files based on last modified date and time. Most recent is at top and old
are at bottom.
7) ls -rt
To display all files based on reverse of last modified date and time. Old files are at top
and recent files are at bottom.
8) ls -a
a means all
To display all files including hidden files. Here . and .. also will be displayed.
9) ls -A
A means almost all
To display all files including hidden files except . and ..
durga@durga-VirtualBox:~$ ls -a
. msmtp.log
.. .msmtprc
.bash_history Music
.bash_logout .mysql_history
.bashrc Pictures
.cache .profile
.config Public
.dbus script1.sh
durga@durga-VirtualBox:~$ la -A
.bash_history .msmtprc
.bash_logout Music
.bashrc .mysql_history
.cache Pictures
.config .profile
.dbus Public
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
19 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
10) ls -F
To display all files by type.
directory /
executable file *
link file @
Eg:
initctl@ Link File
pts/ Directory
ls* Executable File
11) ls -f
To disable colors
12) ls -i
To display all files including inode number.
i-node is the address of location, where file attributes are stored.
i-node is the address of the location, where file attributes are stored.
13) ls -R
R means Recursive.
It will list all files and directories including sub directory contents also. By default ls
will display only direct contents but not sub directory contents.
14) ls -s
The number of blocks used by file will be displayed.
1 Block = 1Kb
Note: In ubuntu each block is of 1KB but not 4KB.
15) ls -h
display in human readable format
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
20 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: If the number of files are very huge, then we can use less and more commands
with ls to display page by page.
$ ls /dev | less
$ ls /dev | more
If we want only fixed number of files either from top or from bottom we have to use head
and tail commands with ls commands.
Note: We can use these options simultaneously. When ever using options simultaneosuly
then the order is not important.
Q1) Write the Command to display all Files including Hidden Files in Last Modifiction Time
Order. Oldest should be First and recent should be Last. It should include Inode
Number and the Number of Blocks used by that File. The Output should be in Long
listing Form?
$ ls -atrisl
131279 4 -rw-r--r-- 1 durga durga 807 Jan 3 12:57 .profile
131277 4 -rw-r--r-- 1 durga durga 3771 Jan 3 12:57 .bashrc
162011 4 -rw-r--r-- 1 durga durga 220 Jan 3 12:57 .bash_logout
132496 4 drwx------ 3 durga durga 4096 Jan 3 13:03 .gnupg
132517 4 drwx------ 3 durga durga 4096 Jan 3 13:03 .local
404481 4 drwxr-xr-x 2 durga durga 4096 Jan 3 13:03 Templates
Q2) Which Command will Lists all Files including Hidden Files along with their Inode
Numbers?
ls -ai
Q3) Which Command will make a Long listing of all the Files in our System including
Hidden Files, sorted by Modification Date (Oldest First)?
ls -latr
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
21 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q4) Is -r will List the Files sorted by Modification Date (Oldest First)?
False.
It lists the files based on reverse of alphabetical order of names.
ls –rt It will list the files sorted by modification date (Oldest first)
2) date Command:
We can use date command to display date and time of system.
Various Options:
1) date +%D
To display only date in the form: mm/dd/yy
2) date +%T
To display only time in the form: hh:mm:ss
3) date +%d
To display only day value
4) date +%m
To display only month value
5) date +%y
To display only year value in yy form
6) date +%Y
To display only year value in yyyy form.
7) date +%H
To display only Hours value (in 24 hours scale format)
8) date +%M
To display only Minutes value
9) date +%S
To display only Seconds value
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
22 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg 2: Create an empty file where file name contains current system date.
touch "durgajobs$(date +%d%m%Y).log"
durgajobs31102019.log
durgajobs01112019.log
durgajobs02112019.log
durgajobs03112019.log
durgajobs04112019.log
Eg 3: Create an empty file where file name contains current system date and time
touch "durgajobs$(date +%d%m%Y%H%M%S).log"
durgajobs31102019205834.log
Note:
If the file name contains date and time then that file is said to be timestamped file (file
with timestamp)
cal Command:
$ cal To display current month calendar.
$ cal 2020 To display total year calendar.
$ cal 1 To display 1st year calendar.
$ cal 9999 To display 9999th year calendar.
$ cal 10000 cal: year '10000' not in range 1..9999
$ cal 08 2019 To display august 2019th calendar
Note: cal command can provide support only for the years 1 to 9999.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
23 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1) mkdir dir1
To create a directory
3) mkdir dir1/dir2/dir3
To create dir3. But make sure dir1 and in that dir2 should be available already.
4) mkdir -p dir1/dir2/dir3
-p means path of directories.
All directories in the specified path will be created.
First dir1 will be created and in that dir2 will be created and within that dir3 will be
created.
jan2020
schedule_1.txt
schedule_2.txt
...
schedule_31.txt
$ mkdir heroines
$ cd heroines
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
24 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ touch
{sunny,katrina,kareena}/{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}_{2020,2021,20
22}/schedule_{1..31}.txt
Case Study-2:
Create 5 directories named with dir6,dir7,dir8,dir9 and dir10. In these directories create
empty files with a.txt,b.txt,c.txt and d.txt
$ mkdir dir{6..10}
$ touch dir{6..10}/{a..d}.txt
Note: *,[],{ } etc are called wild characters. We can use wild card characters in every
command.
Note: rmdir command will work only for empty directories. If the directory is not empty
then we will get error. We cannot use rmdir for files. Hence the most useless (waste)
command in linux is rmdir.
If the directory is not empty then to remove that directory we should use rm command.
All internal content also will be removed. rm command can work for files also. Hence rm is
recommended to use than rmdir.
durga@durga-VirtualBox:~$ rm heroines
rm: cannot remove 'heroines': Is a directory
Whenever we are using rm command for directories, we should use -r or -R option. Here
case is not important.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
25 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ rm -r heroines
$ rm -R heroines
Note: In Linux operating system, there is no way to perform undo operation. Once we
delete a file or directory, it is impossible to retrieve that. Hence while using rm command
we have to take special care.
The following command is the most dangerous command in linux, because it removes
total file system.
rm -r /
2) force removal(-f):
While removing files and directories, if we don't want any error messages, then we should
use -f option. It is opposite to -i option.
durga@durga-VirtualBox:~$ rm -r dir99
rm: cannot remove 'dir99': No such file or directory
durga@durga-VirtualBox:~$ rm -rf dir99
durga@durga-VirtualBox:~$
Even dir99 is not available, we won't get any error message, because we used -f option.
3) verbose Option(-v):
If we want to know the sequence of removals on the screen we should go for -v option.
durga@durga-VirtualBox:~$ rm -r dir6
durga@durga-VirtualBox:~$ rm -rv dir8
removed 'dir8/c.txt'
removed 'dir8/d.txt'
removed 'dir8/a.txt'
removed 'dir8/b.txt'
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
26 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
mkdir dir1/dir2/dir3
Only dir3 will be created and compulsory dir1 and in that dir2 should be avilable
already. If dir1 or dir2 not available then this command won't work.
mkdir -p dir1/dir2/dir3
-p means complete path
All 3 directories will be created.
Ans: C
Ans: B
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
27 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q5) Assume that dir1 is non empty Directory and text1 is just a Text File.
Which of the following Command will remove both dir1 and text1
successfully?
rm text1 dir1
rm -v text1 dir1
rm -R text1 dir1
Ans: C
Q7) How to Create a Directory named A and in that a Directory B and inside
that a Directory C?
-$ mkdir -p A/B/C
Q8) How many Directories will be created after running the following
Command?
$ mkdir {a..c}{1..3}
9 Directories named with a1, a2, a3, b1, b2, b3, c1, c2, c3
Note: In file or directory names, it is not recommended to use space. Instead of that we
have to use _ symbol like java_classes.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
28 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Case Study:
Write commands to create the following directory structure
1st way:
durga@durga-VirtualBox:~$ pwd
/home/durga
durga@durga-VirtualBox:~$ mkdir x y
durga@durga-VirtualBox:~$ cd x
durga@durga-VirtualBox:~/x$ mkdir x1 x2
durga@durga-VirtualBox:~/x$ cd x1
durga@durga-VirtualBox:~/x/x1$ mkdir x11 x12
durga@durga-VirtualBox:~/x/x1$ cd ..
durga@durga-VirtualBox:~/x$ cd ..
durga@durga-VirtualBox:~$ cd y
durga@durga-VirtualBox:~/y$ mkdir y1 y2
durga@durga-VirtualBox:~/y$ cd y1
durga@durga-VirtualBox:~/y/y1$ mkdir y11 y12
2nd way:
$ mkdir x x/x1 x/x2 x/x1/x11 x/x1/x12 y y/y1 y/y2 y/y1/y11 y/y1/y12
3rd way:
$ mkdir -p x/x1/x11 x/x1/x12 x/x2 y/y1/y11 y/y1/y12 y/y2
4th way:
$ mkdir -p x/x{1,2} x/x1/x1{1,2} y/y{1,2} y/y1/y1{1,2}
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
29 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q14) To Remove Directories where Name Starts with 'd' and Ends with 'n'
$ rmdir d*n
Q15) To Remove Directoreis where Name Starts with 'd' OR 'x' $ rmdir [dx]*
Absolute Path:
$ cd /home/durga/y/y2
$ cd ~/y/y2
Relative Path:
$ cd ../../../y/y2
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
30 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Absolute Path:
$ cd /home/durga/x/x1/x11
$ cd ~/x/x1/x11
Relative Path:
$ cd ../../x/x1/x11
Eg 3: Assume we are in x11 directory. To create y21 directory inside y2 without enter into
y2 directory.
Absolute Path:
$ mkdir /home/durga/y/y2/y21
$ mkdir ~/y/y2/y21
Relative Path:
$ mkdir ../../../y/y2/y21
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
31 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ cp -r dir1 dir2
total dir1 will be copied to dir2
Note:
If the destination directory (dir2) already available then total dir1 will be copied to dir2.
If the destination directory (dir2) not already available, then destination directory will be
created and all files of source directory will be copied to destination directory but source
directory won't be copied.
Q16) Write Command to Copy Data from a.txt, b.txt, c.txt to d.txt?
$ cp a.txt b.txt c.txt d.txt It won't work.
We will discuss solution in the next classes.
1) Renaming of files:
$ mv oldname newname
Eg: $ file1.txt file2.txt
file1.txt will be renamed to file2.txt
2) Renaming of Directories:
$ mv dir1 dir2
dir1 will be renamed to dir2
Note: If dir2 is already available then dir1 will be moved to dir2. If dir1 is not already
available then dir1 will be renamed to dir2.
rmdir dir1
rmdir dir1 dir2 dir3
rm -r dir1
rm -ri dir1
rm -rf dir1
rm -rv dir1
rm -r dir*
rm -r dir{2..6}
rm -r dir[2,4]
cp file1.txt file2.txt
cp file1.txt file2.txt file3.txt output
cp dir1/* dir2
cp -r dir1 dir2
mv file1.txt file2.txt
mv dir1 dir2 (rename b'z dir2 not available)
mv dir1/* dir2
mv dir1 dir2 (move dir1 to dir2 because dir2 available)
cd
cd ../../..
cd /
cd ~
cd -
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
33 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1) Creation of Files:
In Linux, we can create files in the following ways:
1) By using touch command (to create empty file)
2) By using cat command
3) By using editors like gedit, vi, nano etc
cat Command:
cat > file1.txt
Eg:
$ cat > file1.txt
Hello Friends
Listen Carefully
Otherwise Linux will give Left and Right
ctrl+d To save and exit
If file1.txt is not already available, then file1.txt will be created with our provided data.
If file1.txt is already available with some content, then old data will be over written with
our provided new data.
Instead of overwriting, if we want append operation then we should use >> with cat
command.
Q2) How we can perform overwriting and appending with cat Command?
> meant for overwriting
>> meant for appending/concatenation
Q3) If we are using Touch Comamnd, but the File is already available then
what will happend?
The content of the file won't be changed. But last modified date and time
(i.e., timestamp) will be updated.
durga@durga-VirtualBox:~$ ls -l file1.txt
-rw-r--r-- 1 durga durga 77 Jan 9 12:24 file1.txt
durga@durga-VirtualBox:~$ touch file1.txt
durga@durga-VirtualBox:~$ ls -l file1.txt
-rw-r--r-- 1 durga durga 77 Jan 9 12:33 file1.txt
Use Case:
Assume that we write one shell script. The job of this shell script is to send all current date
files to remote server. Assume that this script won't be executed on sat and sun. But on
Monday all 3 days files have to be send.
But the problem with this script is it can recognize only current date files. To change
timestamp of sat and Sunday files, we have to use touch command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
35 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: We can use touch command for the following two purposes:
1) To create an empty file.
2) To change timestamp of existing file.
While viewing file content we can include line numbers by using -n option.
While display file content we can skip blank lines by using -b option.
durga@durga-VirtualBox:~$ cat -n file1.txt
1 This is first line
2
3 This is second line
4
5 This is third line
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
36 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
6
7
8 This is extra line
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
37 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
2. tac Command:
It is the reverse of cat.
It will display file content in reverse order of lines. i.e first line will become last line and
last line will become first line.
This is vertical reversal.
3. rev Command:
rev means reverse.
Here each line content will be reversed.
It is horizontal reversal.
Note:
cat command will display total file content at a time. It is best suitable for small files. If the
file contains huge lines then it is not recommended to use cat command. We should go for
head, tail, less and more commands.
4. head Command:
We can use head command to view top few lines of content.
✽ head file1.txt
It will display top 10 lines of file1.txt.
10 is the default value of number of lines.
5. tail Command:
We can use tail command to view few lines from bottom of the file.
It is opposite to head command.
✽ tail file1.txt
Last 10 lines will be displayed.
✽ tail -n +4 file1.txt
It will display from 4th line to last line
6. more Command:
We can use more command to view file content page by page.
✽ more file1.txt
It will display first page.
Enter To view next line
Space Bar To view next page
q To quit/exit
✽ more -d file1.txt
-d option meant for providing details like
--More--(5%)[Press space to continue, 'q' to quit.]
7. less Command:
By using more command, we can view file content page by page only in forward
direction.
If we want to move either in forward direction or in backward direction then we
should go for less command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
39 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
less file1.txt
It will display first page
Eg: Assume a file contains enough data. Write command to display from 3 rd Line to 7th
Line.
1) Katrina Kaif
2) Kareena Kapoor
3) Karishma Kapoor
4) Sunny Leone
5) Mallika Sharawath
6) Sonakshi Sinha
7) Alia Butt
8) Pooja
9) Anushka
10) Deepika
head -7 demo.txt
1. Katrina Kaif
2. Kareena Kapoor
3. Karishma Kapoor
4. Sunny Leone
5. Mallika Sharawath
6. Sonakshi Sinha
7. Alia Butt
tail -5 demo.txt
3. Karishma Kapoor
4. Sunny Leone
5. Mallika Sharawath
6. Sonakshi Sinha
7. Alia Butt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
40 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
touch .securefile1.txt
cat > .securefile1.txt
Even by using editors also we can create hidden files.
mkdir .db_info
Note: By using hidden files and directories we may not get full security. To make more
secure we have to use proper permissions. For this we should use 'chmod' command.
mv a.txt .a.txt
We are converting normal file a.txt as hidden file.
mv .a.txt a.txt
mv dir1 .dir1
mv .dir1 dir1
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
41 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Copying of Files:
cp file1.txt file2.txt
If file2.txt not available, then file2.txt will be created and the content will be copied.
If file2.txt is already available and contanis some data then that data will be overwritten
with file1.txt data.
Before overwriting if we want confirmation, then we should go for -i option.
i means interactive.
cp -i file1.txt file2.txt
$ cp -i a.txt b.txt
cp: overwrite 'b.txt'?
$ cp -v a.txt b.txt
'a.txt' -> 'b.txt'
Note: To copy multiple files content to the single file, we should not use cp command. we
should use cat command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
42 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1) Renaming of Files:
mv oldname newname
mv file1.txt file2.txt
file1.txt will be renamed to file2.txt
2) Renaming of Directories:
mv dir1 dir2
dir1 will be renamed to dir2
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
43 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-8: Comparing
Files
We can compare data of two files by using the following commands:
1) cmp
2) diff
3) sdiff
4) vidiff
5) comm
1) cmp Comamnd:
It will compare byte by byte.
Note: cmp command won't show all differences and show only first difference.
2) diff Comamnd:
It will show all differences in the content.
> chinny
b
3) sdiff Command:
We can use sdiff command for side by side comparison (parallel comparison)
Note: sdiff comamnd and diff command with -y option are same.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
45 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
4) vimdiff Command:
It will highlight differences in vim.
To support this command, we have to install vim by using the following command.
sudo apt install vim
5) comm Command:
By using this command we can compare data of two files.
Pinny
Note: We can compare files from various builds by using our comparison commands
(cmp, diff, sdiff, vimdiff, comm).
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
46 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Case Study:
Requirement-1: assume file1.txt is available inside x11 directory and we are in user home
directory. copy this file to y2 directory.
cp /home/durgasoft/x/x1/x11/file1.txt /home/durgasoft/y/y2
cp ~/x/x1/x11/file1.txt ~/y/y2
cp x/x1/x11/file1.txt y/y2
Requirement-2: assume file1.txt is available inside x11 directory and we are in user home
directory. move this file to y11 directory.
mv /home/durgasoft/x/x1/x11/file1.txt /home/durgasoft/y/y1/y11
mv ~/x/x1/x11/file1.txt ~/y/y1/y11
mv x/x1/x11/file1.txt y/y1/y11
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
47 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-9: Creation of
Link Files
There are 2 types of link files
1) Hard Link files
2) Soft Link files
$ ln dir1 dir2
ln: dir1: hard link not allowed for directory
Note: For files we can create both hard and soft links. But for directories we can create
only softlinks butnot hardlinks.
Case Study:
Assume dir1 contains dir2.
dir2 contains softlink dir3 pointing to dir1
$ mkdir -p dir1/dir2
$ cd dir1/dir2
$ ln -s ~/Desktop/dir1 dir3
Note: While creating link files there may be a chance of forming loops. Take a bit special
care.
Ans: D
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
49 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q2) Which of the following is Valid Way to Create Soft Link for sunny.jpg
Present in Pictures Directory?
A) ln ~/Pictures/sunny.jpg newimg.jpg
B) ln -s ~/Pictures/sunny.jpg newimg.jpg
C) ln newimg.jpg ~/Pictures/sunny.jpg
D) ln -s newimg.jpg ~/Pictures/sunny.jpg
Ans: B
Q3) We can Create both Hard and Soft Links to the Directories. Is it Valid?
A) True
B) False
Ans: B
Note: If we perform any change to the content of original file, then these changes will be
reflected to the link file. Similarly, if we perform any change to the link file, then those
changes will be reflected to the original file. This is true for both hard and soft links.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
50 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
wc filename
no_of_lines no_of_words no_of_characters filename
Eg:
$ wc a.txt
4 26 166 a.txt
4 Number of Lines
26 Number of words
166 Number of characters (File size in bytes)
$ wc -l a.txt
4 a.txt
$
$ wc -w a.txt
26 a.txt
$ wc -c a.txt
166 a.txt
$ wc -lw a.txt
4 26 a.txt
$ wc -lc a.txt
4 166 a.txt
$ wc -wc a.txt
26 166 a.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
51 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ wc -L a.txt
57 a.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
52 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-11: Sorting
Content of the File
We can sort data of the file by using sort command.
sort filename
Here sorting is based on alphabetical order.
$ cat a.txt
Sunny
Bunny
Chinny
Vinny
Pinny
$ sort a.txt
Bunny
Chinny
Pinny
Sunny
Vinny
If we want to sort based on reverse of alphabetical order, then we should use -r option.
$ sort -r a.txt
Vinny
Sunny
Pinny
Chinny
Bunny
If the file contains alphanumeric data, then first numbers will be considered and then
alphabet symbols.
$ cat a.txt
7
Sunny
8
Bunny
1
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
53 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Chinny
6
Vinny
5
Pinny
$ sort a.txt
1
5
6
7
8
Bunny
Chinny
Pinny
Sunny
Vinny
$ sort -r a.txt
Vinny
Sunny
Pinny
Chinny
Bunny
8
7
6
5
1
If the file contains only numbers, then the sorting is not based on numeric value and it is
just based on digits.
$ sort a.txt
11
2
2222222
7
9
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
54 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ sort -n a.txt
2
7
9
11
2222222
Bydefault sort command will display duplicate lines. If we want only unique lines then we
have to use -u option.
-u meant for unique lines.
$ cat a.txt
1
1
2
2
Sunny
Sunny
Bunny
$ sort a.txt
1
1
2
2
Bunny
Sunny
Sunny
$ sort -u a.txt
1
2
Bunny
Sunny
Without using -r option with sort command, sort the content based on reverse of
alphabetical order and store the result inside sorted.txt?
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
56 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
57 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ cat a.txt
Sunny
sunny
Bunny
Chinny
Sunny
Bunny
Chinny
$ uniq a.txt
Sunny
sunny
Bunny
Chinny
Sunny
Bunny
Chinny
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
58 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
59 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Commands can take input, perform required operation and produces some output.
While executing command if anything goes wrong then we will get error message.
Command can take input either from standard Input or from command line arguments.
Command will produce results to either Standard output or Standard Error.
Standard Input, Standard Output and Standard Error are Data Streams and can flow from
one place to another place. Hence redirection and piping are possible.
Command Line arguments are static and these are not streams. Hence redirection and
piping concepts are not applicable to command line arguments.
Bydefault Standard input connected with keyboard, Standard output and Standard Error
connected with Terminal. But we can redirect.
Note: For the cat command if we are not providing any arguments, then the input will be
taken from standard input device (keyboard) and display the output to the standard
output device (Terminal).
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
60 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ cat
This is data provided from Standard Input
This is data provided from Standard Input
Note: Some commands may accept Standard Input and Some commands may accept
command line arguments.
1) rm command will always accept command line arguments only.
rm file1 file2
2) echo command will always aceept command line arguments only.
echo "durgasoft"
3) cat command can accept input either from standard input or from comamnd line
arguments.
Redirection
As Standard Input, Standard Ouput and Standard Error are Data streams, we can redirect
these streams.
sample data won't be displayed to the terminal and will write to output.txt
Redirection symbol > is always associated with 1 by default. Hence we are not required to
specify 1 explicilty.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
61 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Now error message won't be displayed to the console and will written to error.txt.
For error redirection 2 is mandatory.
***Note: To redirect both standard output and standard error to the same destination we
can use shortcut as follows
termainal - 2:
$ tty
/dev/pts/1
terminal - 1:
$ls -l 1> /dev/pts/1
Bits
Q1) In How Many Ways Command can get Input?
2 ways. Either from Standard Input or from command line arguments.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
63 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
64 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-14: Piping
Sometimes we can use output of one command as input to another command. This
concept is called piping.
By using piping, multiple commands will work together to fulfill our requirement.
$ ls -l /etc | wc
215 1940 11872
First ls got executed and the output of this command will become input to wc command.
Eg 2: $ ls -l /etc | more
Eg 3: $ ls -l /etc | wc |wc -l
The output is: 1
Eg 4: $ ls -l /etc | head -5
Note: instead of ls -l we can use ll command, most of linux flavours provides support.
tee Command:
Requirement:
The output of the ls command should be saved to output.txt and should be provided as
input to wc command:
ls -l 1>output.txt | wc
This command won't work because if we are using redirection in the middle of piping, it
will break piping concept.
In piping, if we want to save the output of one command to a file and if we want to pass
that output as input to next command simultaneously, then we should go for tee
command.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
65 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
tee command is just like T-Junction or T-Pipe. It will take one input but provides two
outputs.
Eg 2: To save the output of ls command to a file and send that output as input to wc
command
$ ls -l | tee output.txt | wc -l
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
66 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
xargs Command:
Q1) Display the Output of Date Command by using echo
Command with Piping Concept?
$ date | echo It won't work because the output of date command is stream, but
echo command will accept only command line arguments but not stream.
$ date | xargs echo xargs command will convert the output stream of date
command into command line arguments and these arguments will be passed as
input to echo command.
Hence the job of xargs command is to convert output stream into command line
arguments
Eg 1: Assume input.txt contains file names. Each file contains some data.
Read file names from the input.txt, write total content to output.txt and display the total
number of lines present in output.txt.
Eg 2: Assume input.txt contains file names. Read file names from the input.txt and remove
all these files.
Assignment:
list out all contents of /dev folder and save to file1.txt.
list out all contents of /bin folder and save to file2.txt.c
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
67 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q4) How we can use tee Command when Piping together Commands A, B
and C to save Output of B Command to results.txt.
A | B | tee results.txt | C
Q5) How to Pipe Data from Command A to Command B, but B won't accept
Standard Input and accepts only Command Line Arguments?
A | xargs B
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
68 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
First cmd1 will be executed and then cmd2 followed by rest of the commands.
If any command fails in the middle, still rest of the commands will be executed.
First cmd1 will be executed and then cmd2 followed by rest of the commands.
If any command fails in the middle, then rest of the commands won't be executed.
Eg:
create a directory dir1
create files a.txt,b.txt,c.txt in that dir1
write current system date and time to a.txt
write current month calendar to b.txt
mkdir dir1 ; touch dir1/{a,b,c}.txt ; date > dir1/a.txt ; cal > dir1/b.txt
mkdir dir1 && touch dir1/{a,b,c}.txt && date > dir1/a.txt && cal > dir1/b.txt
mkdir dir1 ; touch dir1/{a,b,c}.txt ; Date > dir1/a.txt ; cal > dir1/b.txt
Here 3rd command fails, but still 4th command will be executed.
mkdir dir1 && touch dir1/{a,b,c}.txt && Date > dir1/a.txt && cal > dir1/b.txt
Here 3rd command fails, and hence 4th command won't be executed.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
69 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
A wildcard character can be used as a substitute for required sequence of characters in the
regular expression.
4) To list out all files starts with a and ends with t $ ls a*t
6) To list out all files where file name contains only 2 characters and first character
should be 'a' $ ls a?
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
70 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
7) To list out all files where file name contains only 3 characters $ ls ???
8) To list out all files where file name contains atleast 3 characters $ ls ???*
9) To list out all files where file name starts with a or b or c $ ls [abc]*
10) To list out all files where file name should not starts with a, b and c $ ls [!abc]*
11) To list out all files starts with lower case aphabet symbol
$ ls [a-z]* OR $ls [[:lower:]]*
12) To list out all files starts with upper case aphabet symbol
$ ls [A-Z]* OR $ls [[:upper:]]*
14) To list out all files where first letter should be upper case alphabet symbol, second
letter should be digit and third letter should be lower case alphabet symbol.
$ ls [[:upper:]][[:digit:]][[:lower:]]
16) To list out all files with .java and .py extension
$ ls {*.java, *.py}
Note: We can use these wildcard characters with the following commands also.
cp, mv, rm
18) To move all files starts with alphabet symbol and with .txt extension to dir2 directory?
$mv [[:alpha:]]*.txt dir2
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
71 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q1) Which of the following Command will List all Files that has
exactly 3 Characters Present in Current Working Directory?
A) ls ***
B) ls ???
C) ls !!!
D) ls &&&
Ans: B
Q2) Which of the following Commands will Copy all Files that Ends
with .pdf to dir1?
A) cp ?.pdf dir1
B) cp .pdf* dir1
C) cp *.pdf dir1
Ans: C
Q3) Which of the following Command will move all the Files that
begins with Letter a and Ends with Letter n to dir1?
$mv a*n dir1
Q5) Which of the following Commands will List all Files that begins
with a Lower Case Alphabet Symbol and has a Letter d in the
3rd Character Position, and Ends with an Upper Case Letter?
$ls [[:lower:]]?d*[[:upper:]]
Q6) Which of the following Command will List all .jpg Files Present
in Pictures Directory?
$ls /home/durgasoft/Pictures/*.jpg
$ls ~/Pictures/*.jpg
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
72 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q7) Which of the following Regular Expressions will Match the File
named with demoA.txt ?
A) *
B) demo?.txt
C) demo*
D) *.txt
E) demo[A-Z].txt
F) All of these
A) ??.pdf
B) report*.pdf
C) *[A-Z].pdf
D) student*.pdf
Ans: C, D
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
73 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-17: Command
Aliasing
Alias means other alternative name or nickname.
We can give our own more convinient nicknames for unix commands. This concept is
called command aliasing.
Note: we can use type command, to check whether the command is already available or
not.
After aliasname space is not allowed. Hence the following are invalid
alias nickname ='original command'
alias nickname= 'original command'
alias nickname = 'original command'
$d20f
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
74 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg: To list out all files present in current working directory, save this data to output.txt
and display the number of lines to the terminal. Define alias name 'current' for this total
activity.
alias cls='clear'
alias rename='mv'
alias grpe='grep'
alias datum='date'
But we can make our created aliases permanently in our system by using the following 2
ways:
1st Way:
We have to define our aliases in .bashrc file present in our home directory.
gedit .bashrc
# myown aliases
alias cls='clear'
alias ddd='date;date;date'
Note: To reflect these aliases, compulsory we have to close and open terminal.
2nd Way:
Instead of editing .bashrc file, we can create our own file to maintain our defined aliases.
The name of the file should be .bash_aliases and should be present in home directory.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
75 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
.bash_aliases
alias ccc='cal;cal;cal'
alias ct='cal;date'
Note: To reflect these aliases, compulsory we have to close and open terminal.
Ans: D
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
76 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Internally locate command will search in the database for the required files and
directories and returns the results.
To ignore case:
By default locate command will consider case. If we want to ignore case, we have to use -i
option.
$locate -i *.jpg
We can limit the number of lines in the result by using --limit option.
$ locate --limit 5 *.conf
/etc/adduser.conf
/etc/apg.conf
/etc/appstream.conf
/etc/brltty.conf
/etc/ca-certificates.conf
Before display results, to check whether the file exists or not , we have to use -e option or
--existing option.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
77 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Reason:
locate command using database to find results. This database will be updated only once
per day bydefault. After updating database, some files may be deleted. Hence before
printing results, to check whether files are existing or not, we have to use -e or --existing
option.
Before displaying results, to check whether symbolic links pointing to original files or not,
we have to use -L or --follow option. i.e if we use --follow option, broken symbolic links
won't be displayed in the output.
$ locate -S
Database /var/lib/mlocate/mlocate.db:
39,527 directories
3,69,078 files
2,42,42,520 bytes in file names
93,40,974 bytes used to store database
This database will be updated only once per day. If we are creating or removing files and
directories, to reflect these changes we have to update database explicitly by using
updatedb command. But admin privileges must be required.
$ sudo updatedb
[sudo] password for durgasoft:
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
78 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q3) We created a File called demo.txt. But it has been 2 Hours since locate
Database has been updated. Is locate Command able to find this
demo.txt?
A) Yes
B) No
Ans: No
find Command:
We can use find command to find files and directories present in our system.
It provides more search options when compared with locate command like
1) Search only files
2) Search only directories
3) Search by name
4) Search by size
5) We can use search results automatically for some other commands
6) We can restrict maxdepth
etc
1. $find
It will find all files and directories in current working directory and below in linux file
system. This is the default behaviour.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
79 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
2. We can find all files and directories in the specified directory and below.
$ find /dev
$ find /etc
3. maxdepth Option:
usually find command will search in all depth levels. But we can specify the required depth
level by using maxdepth option.
Desktop
|-file1.txt
|-level_1_dir
|-file2.txt
|-levlel_2_dir
|-file3.txt
|-level_3_dir
|-file4.txt
|-level_4_dir
|-file5.txt
$mkdir -p level_1_dir/level_2_dir/level_3_dir/level_4_dir
$touch file1.txt level_1_dir/file2.txt level_1_dir/level_2_dir/file3.txt
level_1_dir/level_2_dir/level_3_dir/file4.txt
level_1_dir/level_2_dir/level_3_dir/level_4_dir/file5.txt
1. $ find . -maxdepth 1
2. $ find . -maxdepth 2
3. $ find . -maxdepth 3
4. $ find . -maxdepth 4
5. $ find . -maxdepth 100
Note:
1. For maxdepth option we should use singl - but not double --
-maxdepth Valid
--maxdepth Invalid
2. find command will find hidden files and directories also.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
80 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Find by Type:
We can find only files or only directories by using type option.
-type f means only files
-type d means only directories
Note: We can use these options simultaneously, but we should use first -maxdepth and
then -type.
Find by Name:
We can find files and directories by name by using -name option.
$ touch {A..D}.txt
$ touch {A,B}{A,B}.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
81 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
2. To list out all file names where size is over 200kb but less than 4MB.
$ find / -type f -size +200k -size -4M | wc -l
3. To list out all file names where file size is less 200kb or more than 4MB.
$ find / -type f -size -200k -o -size +4M | wc -l
-o means or
Note:
+n for greater than n
-n for less than n
n for exactly n
Q3) To Copy all Files Present in /etc Folder where File Size is
< 2KB to dir1 Directory Present in the Desktop?
$ find /etc -type f -size -2k -exec cp {} dir1 \;
Magic Assignment:
$ mkdir magic
$ mkdir magic/dir{1..100}
$ touch magic/dir{1..100}/file{1..100}.txt
Q4) The Find Command Uses a Database to Search Files and Directories
A) True
B) False
Ans: B
Q5) To find Files and Directories inside /dev Folder and Limit its Search to
only 2 Levels of Deep?
A) find -start /dev -depth 2
B) find /dev -depth 2
C) find /dev -maxdepth 2
Ans: C
Q6) To find only Directories inside /dev Folder and Limit its Search to only 2
Levels of Deep?
A) find /dev -maxdepth 2 -type f
B) find /dev -maxdepth 2 -type d
C) find /dev -type d -maxdepth 2
Ans: B
Q7) To find only Files Starts from Root Directory (/) where File Name Ends
with .txt?
A) find / '*.txt'
B) find / -type d -name '*.txt'
C) find / -type f -name '*.txt'
Ans: C
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
83 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q8) To find all Files and Directories inside /dev Directory upto Maximum of 3
Levels Deep and Size is Greater than 200 Kilo Bytes?
A) find / -maxdepth 3 -size 200k
B) find /dev -maxdepth 3 -size 200k
C) find /dev -maxdepth 3 -size -200k
D) find /dev -maxdepth 3 -size +200k
Ans: D
Q9) Which of the following Command will find all Files below our Home
Directory where File Size is Greater than 3 Mega Bytes and Remove all
those Files?
A) find ~ -type f -size +3M -exec rm {} \;
B) find ~ -type f -size -3M -exec rm {}
C) find ~ -type f -size -3M -exec rm {} \;
D) find ~ -type f -size +3M rm {} \;
Ans: A
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
84 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
85 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
2) To uncompress gz file:
$ gzip -d demo.tar.gz OR $ gunzip demo.tar.gz
This command will provide our original tar file
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
86 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$mkdir newhome
$mv backup.tar newhome
$cd newhome
$ tar -xvzf backup.tar
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
87 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-20: grep
Command
grep stands for
globally search a regular expression and print it
global regular expression print.
global regular expression parser.
We can use grep command to search the given pattern in a single or multiple files.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
88 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ grep durga *
career.txt:durga
career.txt:durga ksdjfdlakjklfjad
subjects.txt:3. unix durga 250
subjects.txt:5. UNIX durga 400
subjects.txt:6. Java durga 1000
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
89 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg 1:
durgasoft@durgasoft:~/Desktop$ grep -i unix demo.txt
UnixDemo session
unix material
durgasoft@durgasoft:~/Desktop$ grep -iw unix demo.txt
unix material
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
90 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg 2:
durgasoft@durgasoft:~/Desktop$ grep -in unix demo.txt
5:UnixDemo session
6:unix material
9:UNIX classes and videos
durgasoft@durgasoft:~/Desktop$ grep -win unix demo.txt
6:unix material
9:UNIX classes and videos
-A means after
-B means before
-C means before and after
Note: C is optional.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
91 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: fgrep can be used only for Strings and cannot be used for regular expressions.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
92 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Normal grep command cannot understand some regular expression patterns like |
symbol. But egrep command can understand any regular expression pattern. Hence egrep
is the more powerful than normal grep command.
Eg:
durgasoft@durgasoft:~/Desktop$ cat demo.txt
This is java demo
UnixDemo session
unix material
UNIX classes and videos
java is slowly going down
(java|unix) this is extra line added
durgasoft@durgasoft:~/Desktop$ grep -i "(java|unix)" demo.txt
(java|unix) this is extra line added
In this case (java|unix) is considered as a string and cannot be processed as regular
expression.
In this case, (java|unix) is treated as regular expression. It will search for either java or
unix.
egrep and fgrep are deprecated and hence it is recommend to use grep -E and grep -F
commands.
If strings are available in the file, then we can use -f option to specify file name.
unix material
dsfjalkjfdlsda
sadkfjklsadjfkld
UNIX classes and videos
java is slowly going down
demounix
unixforall
grtgrgtujmik, fgtunix dghjhrunix fghubunixdfgghj
file1.txt
java
unix
python
demo
-i,-n,-c,-v,-l,-A,-B,-C,-e,-E, -F,-f, -o, -R
call center
cell point
college for unix
durgasoft@durgasoft:~/Desktop$ fgrep c[aeiou]ll demo.txt
c[aeiou]ll point for fgrep
durgasoft@durgasoft:~/Desktop$ egrep c[aeiou]ll demo.txt
call center
cell point
college for unix
resumes
java
students.txt
python
students.txt
testing
students.txt
$ mkdir resumes
Note: If we want to use grep command for directory, compulsory we should use -R
option, which means recursive.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
95 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Assignment:
1. Save all running processes information inside a file.
$ ps -ef > results.txt
5. Display all lines which contain 'lib' and preceding with line numbers?
$ grep -n 'lib' results.txt
6. Display lines which do not contain 'lib', but only top 2 lines.
$ grep -v 'lib' results.txt | head -2
Assignment-2:
durgasoft@durgasoft:~/Desktop$ cat emp.dat
eno|ename|esal|eaddr|dept|gender
100|sunny|1000|mumbai|admin|female
200|bunny|2000|chennai|sales|male
300|chinny|3000|delhi|accounting|female
400|vinny|4000|hyderabad|admin|male
500|pinny|5000|mumbai|sales|female
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
96 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1) Character Patterns
2) Word Patterns
3) Line Patterns
1) Character Patterns:
1) $ grep 'd*' demo.txt
It display all lines which contains d followed by any number of characters.
ubuntu not providing support for this.
2) Word Patterns:
\<word\> It will always searches for the given word
It is exactly same as
grep -w word demo.txt
durga
techdurga
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
99 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
3. {m,n} The preceding character should match minimum m times and maximum n
times.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
100 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
101 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
emp.dat
eno|ename|esal|eaddr|dept|gender
100|sunny|1000|mumbai|admin|female
200|bunny|2000|chennai|sales|male
300|chinny|3000|delhi|accounting|female
400|vinny|4000|hyderabad|admin|male
500|pinny|5000|mumbai|sales|female
$cut -c 5- emp.dat
It will display 5th character to last character in every record
$ cut -c -3 emp.dat
It will display from 1st character to 3rd character in every record.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
102 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
paste Command:
We can use paste command to join two or more files horizontally by using some delimiter.
Default delimiter is tab.
Eg:
durgasoft@durgasoft:~/Desktop$ cat > subjects.txt
Core Java
Adv Java
Python
Django
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
103 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
UNIX
durgasoft@durgasoft:~/Desktop$ cat > fee.txt
1000
2000
2500
1500
250
durgasoft@durgasoft:~/Desktop$ paste subjects.txt fee.txt
Core Java 1000
Adv Java 2000
Python 2500
Django 1500
UNIX 250
Note: Delimiter should be only one character. If we are providing more than one
character, then it will consider only first character.
tr Command:
tr means translate.
This command translates character by character.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
104 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
105 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-22: File
Permissions
File Permissions describe the allowed operations by various users.
With respect to file permissions, all users are categorized into the following 4 types.
User Categories:
user/owner Represented by 'u'
group Represented by 'g'
others Represented by 'o'
all Represented by 'a'
1) STUDENTS MODULE
A, B, C, D ARE WORKING
2) EMPLOYEES MODULE
X, Y, Z ARE WORKING
3) COURSES MODULE
M, N ARE WORKING
4) INFRASTRUCTURE MODULE
G, H ARE WORKING
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
106 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
For demo.txt
user/owner: A (The person who created the file)
group: B,C,D (The persons who are working in the same module)
others: X,Y,Z,M,N,G,H (The persons who are working on other modules)
Permission Types:
For files and directories, there are 4 types of permissions.
1) r Read
2) w Write
3) x Execute
4) - No Permission
Table_FilePermissions
chmod Command:
chmod means change mode.
We can use chmod command to change file or directory permissions.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
107 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg: For user add execute permission,for group add write permission,for others remove
read permission
$ chmod u+x,g+w,o-r demo.txt
Note: Only owner and super user (root) can change file permissions.
durgasoft@durgasoft:~/Desktop$ ls -l
total 0
-rw-r--r-- 1 durgasoft durgasoft 0 Nov 27 21:19 demo.txt
Total 9 permissions. First 3 are user permissions, next 3 are group permissions and next 3
are others permissions.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
108 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/Desktop$ ls -l
total 4
-rw-r--r-- 1 durgasoft durgasoft 34 Nov 28 20:56 demo.txt
durgasoft@durgasoft:~/Desktop$ cat demo.txt
This is file content at beginning
durgasoft@durgasoft:~/Desktop$ chmod u-r demo.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
109 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/Desktop$ ls -l first.sh
-rw-r--r-- 1 durgasoft durgasoft 82 Nov 28 21:10 first.sh
durgasoft@durgasoft:~/Desktop$ ./first.sh
bash: ./first.sh: Permission denied
durgasoft@durgasoft:~/Desktop$ chmod u+x first.sh
durgasoft@durgasoft:~/Desktop$ ls -l first.sh
-rwxr--r-- 1 durgasoft durgasoft 82 Nov 28 21:10 first.sh
durgasoft@durgasoft:~/Desktop$ ./first.sh
Hello Friends...
File Permissions is very very important than Sunny
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
110 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/Desktop$ ls -l
total 4
drwxr-xr-x 2 durgasoft durgasoft 4096 Nov 28 21:18 dir1
durgasoft@durgasoft:~/Desktop$ ls dir1
demo.txt first.sh
durgasoft@durgasoft:~/Desktop$ chmod u-r dir1
durgasoft@durgasoft:~/Desktop$ ls -l
total 4
d-wxr-xr-x 2 durgasoft durgasoft 4096 Nov 28 21:18 dir1
durgasoft@durgasoft:~/Desktop$ ls dir1
ls: cannot open directory 'dir1': Permission denied
durgasoft@durgasoft:~/Desktop$
durgasoft@durgasoft:~/Desktop$ ls -l
total 4
dr-xr-xr-x 2 durgasoft durgasoft 4096 Nov 28 21:18 dir1
durgasoft@durgasoft:~/Desktop$ touch dir1/newfile.txt
touch: cannot touch 'dir1/newfile.txt': Permission denied
durgasoft@durgasoft:~/Desktop$ rm -f dir1/demo.txt
rm: cannot remove 'dir1/demo.txt': Permission denied
durgasoft@durgasoft:~/Desktop$ chmod u+w dir1
durgasoft@durgasoft:~/Desktop$ ls -l
total 4
drwxr-xr-x 2 durgasoft durgasoft 4096 Nov 28 21:18 dir1
durgasoft@durgasoft:~/Desktop$ touch dir1/newfile.txt
durgasoft@durgasoft:~/Desktop$ rm -f dir1/demo.txt
durgasoft@durgasoft:~/Desktop$ ls dir1
first.sh newfile.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
111 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/Desktop$ ls -l
drwxr-xr-x 2 durgasoft durgasoft 4096 Nov 28 21:26 dir1
durgasoft@durgasoft:~/Desktop$ chmod u-x dir1
durgasoft@durgasoft:~/Desktop$ ls -l
total 4
drw-r-xr-x 2 durgasoft durgasoft 4096 Nov 28 21:26 dir1
\durgasoft@durgasoft:~/Desktop$ cd dir1
bash: cd: dir1: Permission denied
durgasoft@durgasoft:~/Desktop$ chmod u+x dir1
durgasoft@durgasoft:~/Desktop$ cd dir1
***Note: If the user not having execute permission on any directory, then he cannot
perform read and write operations also, because to perform these operations he should
enter into that directory which is not possible.
Note: If the user not having read permission on any file, then he cannot execute that file
even though he has executed permission.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
112 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Linux vs Security:
The virus files usually created by others.
others are not having execute permission on our directories. Hence others are not allowed
to add virus files to our directories.
Hackers are not having executed permission on our directories. Hence they cannot read
our file data.
Note: We are using permission types as r,w,x and these are considered as symbolic
permissions. But we can also specify permissions by using octal number, such type of
permissions are called numeric permissions.
Numeric Permissions:
We can specify permissions by using octal number.
Octal means base-8 and allowed digits are 0 to 7.
0 000 No Permission
1 001 Execute Permission
2 010 Write Permission
3 011 Write and execute Permissions
4 100 Read Permission
5 101 Read and execute Permissions
6 110 Read and write Permission
7 111 Read, Write and execute Permissions
Note:
4 Read Permission
2 Write Permission
1 Execute Permission
$ chmod 77 demo.txt
durgasoft@durgasoft:~/Desktop$ ls -l demo.txt
----rwxrwx 1 durgasoft durgasoft 0 Nov 29 20:57 demo.txt
77 means 077
$ chmod 7 demo.txt
durgasoft@durgasoft:~/Desktop$ ls -l demo.txt
-------rwx 1 durgasoft durgasoft 0 Nov 29 20:57 demo.txt
7 means 007
$ chmod demo.txt
durgasoft@durgasoft:~/Desktop$ chmod demo.txt
chmod: missing operand after ‘demo.txt’
Try 'chmod --help' for more information.
$ chmod 0 demo.txt
durgasoft@durgasoft:~/Desktop$ ls -l demo.txt
---------- 1 durgasoft durgasoft 0 Nov 29 20:57 demo.txt
umask Command:
umask means user mask. Hiding permissions.
Based on umask value,default permissions will be there for files and directories.
The default umask value:022
durgasoft@durgasoft:~/Desktop$ umask
0022
First 0 is sticky bit mostly used in admin related activities. We have to consider only last 3
digits as umask value.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
114 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/Desktop$ ls -l file1.txt
-rw-r--r-- 1 durgasoft durgasoft 0 Nov 29 21:18 file1.txt
$ mkdir dir1
$ ls -l
drwxr-xr-x 2 durgasoft durgasoft 4096 Nov 29 21:21 dir1
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
115 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
chown Command:
chown means change owner.
Only root user can perform this activity.
chgrp Command:
chgrp means change group.
Only root user can perform this activity.
durgasoft@durgasoft:~$ sudo -i
[sudo] password for durgasoft:
root@durgasoft:~#
root@durgasoft:~# whoami
root
root@durgasoft:~# cd /home/durgasoft/Desktop
root@durgasoft:/home/durgasoft/Desktop# ls
demo.txt
root@durgasoft:/home/durgasoft/Desktop# ls -l
total 0
-rw-r--r-- 1 durgasoft durgasoft 0 Nov 29 21:33 demo.txt
root@durgasoft:/home/durgasoft/Desktop# chown root demo.txt
root@durgasoft:/home/durgasoft/Desktop# ls -l
total 0
-rw-r--r-- 1 root durgasoft 0 Nov 29 21:33 demo.txt
root@durgasoft:/home/durgasoft/Desktop#
Case Study:
-rwxrw-r-- 1 root durgasoft 42 Nov 30 19:47 demo.txtowner: root
group: durgasoft
Group members can perform both read and write operations.
Eg 2:
-rwxrwxr-- 1 root root 90 Nov 30 19:55 demo.txt
owner: root
group: root
others can perform only read operation.
duragsoft user can perform only read operation
durgasoft@durgasoft:~/Desktop$ cat demo.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
116 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Group Permissions:
durgasoft durgasoft
Others Permissions:
-rwxrwxr-- 1 root root 114 Nov 30 20:22 demo.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
117 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-23: Working
with Editors
We can use editors to edit file content.
There are multiple editors are available.
1) geditor
2) vi editor
3) nano editor
etc
$ gedit file1.txt
$ gedit first.sh
Note: gedit can work only in the desktop version and cannot work in server version.
By using putty if we are connecting remote server, then we cannot use gedit and
compulsory we should go for vi editor.
vi editor is unix based where as gedit and nano are linux based.
vi can work anywhere.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
118 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ vi file1.txt
If file1.txt is not available, then a new file will be created and opened that file for
editing purpose.
To save this empty file we should use :wq (w means save and q means exit)
If the file already contains some data then editor will be opened that file and ready for
edit.
1) Command Mode:
It is the default mode.
Here we can use any vi command.
From command mode, we can enter into insert mode by using multiple ways, but
mostly by using i.
3) Exit Mode:
To quit from the editor.
From the command mode we have to press: then we can enter into exit mode.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
119 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
120 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
We are not required to use these because keyboard arrow keys aleady working.
b(nb) Back to beginning of the Word
3b Back to beginning of the 3rd (ie 3rd previous Word)
e(ne) End of the Current Word
w(nw) Forward to beginning of next Word.
at exit mode
:1 To go to 1st line
:7 To go to 7th line
Note: If we want to perform undo previous operation then we should use 'u'
u Means undo previous operation
Eg:
:!date To check system date
:!cal To check calander
Note: vi +7 demo.txt
open demo.txt and enter into 7th line
Various Options:
ctrl+g (F1) Display this help text
ctrl+x (F2) Close the current file buffer / Exit from nano
ctrl+o (F3) Write the current file to disk
ctrl+r (F5) Insert another file into the current one
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
122 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Part-2
Shell Scripting
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
123 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Agenda
Topic-24: Shell Scripting / Shell Programming:
Topic-30: Operators
Topic-32: Arrays
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
124 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Types of Shells:
There are multiple types of shells are available.
1) Bourne Shell:
It is developed by Stephen Bourne.
This is the first shell which is developed for UNIX.
By using sh command we can access this shell.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
125 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
2) BASH Shell:
BASH Bourne Again SHell.
It is advanced version of Bourne Shell.
This is the default shell for most of the linux flavours.
By using bsh command we can access this shell.
3) Korn Shell:
It is developed by David Korn.
Mostly this shell used in IBM AIX operating system.
By using ksh command, we can access this shell.
4) CShell:
Developed by Bill Joy.
C meant for California University.
It is also by default available with UNIX.
By using csh command, we can access this shell.
5) TShell:
T means Terminal.
It is the advanced version of CShell.
This is the most commonly used shell in HP UNIX.
By using tcsh command, we can access this shell.
6) Z Shell:
Developed by Paul.
By using zsh command we can access this shell.
Note: The most commonly used shell in linux environment is BASH. It is more powerful
than remaining shells.
We can also check the default shell information inside /etc/passwd file
$ cat /etc/passwd
durgasoft:x:1000:1000:durgasoft,,,:/home/durgasoft:/bin/bash
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
126 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/bin/rbash
/bin/dash
durgasoft@durgasoft:~/Desktop$ sh
$ echo $0
sh
$ exit
durgasoft@durgasoft:~/Desktop$ echo $0
bash
durgasoft@durgasoft:~/Desktop$ rbash
durgasoft@durgasoft:~/Desktop$ echo $0
rbash
durgasoft@durgasoft:~/Desktop$ exit
exit
durgasoft@durgasoft:~/Desktop$ dash
$ echo $0
dash
$ exit
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
127 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Inside shell script, we can also use programming features like conditional statements,
loops, functions etc. Hence we can write scripts very easily for complex requirements also.
demo.sh:
echo "Welcome to shell script"
date
cal
$ /bin/bash ./demo.sh
$ bash ./demo.sh
$ /bin/bash /home/durgasoft/scripts/demo.sh
$ ./demo.sh # default shell is bash
Note: The default shell is bash. Hence bash is responsible to execute our script.
Instead of bash, if we want to use Bourne shell then we have to use the following
command
$ /bin/sh ./demo.sh
$ sh ./demo.sh
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
128 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Importance of Sha-Bang:
By using sha-bang, we can specify the interpreter which is responsible to execute the
script.
# Sharp
! Bang
#! Sharp Bang or Shabang or Shebang
If we write shabang in our script at the time of execution, we are not required to provide
command to execute and we can execute script directly.
Without Shabang:
$ python3 ./test.py
$ python3 /home/durgasoft/scripts/test.py
With Shabang:
$ ./test.py
$ /home/durgasoft/scripts/test.py
It is equivalent to
$ rm ./demo.sh
demo.sh will be removed as this script executed by rm command.
Q3) Write and Run Shell Script that Prints Current System
Date and Time
date.sh
#! /bin/bash
echo "The current System Date and Time:"
date
Q4) How to Run Our Script from any where in our System?
For any command or script, by default shell will check locations specified by PATH
variable.
If we add our script location to PATH Variable value, then we can run our script
from anywhere in our system. We can do this in the following two ways:
1) Session Level:
durgasoft@durgasoft:~/scripts$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
/snap/bin
$ export PATH=$PATH:/home/durgasoft/scripts
Now we can run our script from anywhere. We are not required to provide either absolute
path or relative path.
$date.sh
The current System Date and Time:
Wed Dec 4 21:01:49 IST 2019
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
130 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: This way of setting PATH variable is applicable only for current session. Once we
close terminal then automatically these changes will be lost.
export PATH=$PATH:/home/durgasoft/scripts
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
131 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-26: Shell
Variables
Variables are place holders to hold values.
Variables are key-value pairs.
In Shell programming, there are no data types. Every value is treated as text type/ String
type.
1) Environment Variables:
These are predefined variables and mostly used internally by the system. Hence these
variables also known as System variables.
But based on our requirement, we can use these variables in our scripts.
We can get all environment variables information by using either env command or set
command.
durgasoft@durgasoft:~$ env
LANG=en_IN
USERNAME=durgasoft
USER=durgasoft
PWD=/home/durgasoft
HOME=/home/durgasoft
SHELL=/bin/bash
LOGNAME=durgasoft
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/
games:/snap/bin:/home/durgasoft/scripts
...
durgasoft@durgasoft:~$ set
BASH=/bin/bash
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
132 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
LANG=en_IN
LOGNAME=durgasoft
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/
games:/snap/bin:/home/durgasoft/scripts
PS1='\[\e]0;\u@\h:
\w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[0
1;34m\]\w\[\033[00m\]\$ '
PWD=/home/durgasoft
SHELL=/bin/bash
durgasoft@durgasoft:~$
durgasoft@durgasoft:~$ PS1=DURGA$
DURGA$ls
abc.txt Documents d.txt Pictures scripts Videos y
Desktop Downloads Music Public Templates x
DURGA$cat > abc.txt
asdfjkasjfdsa
asfdkasklfdjlads
DURGA$PS1=Sunny#
Sunny#ls -l
total 52
-rw-r--r-- 1 durgasoft durgasoft 31 Dec 5 20:58 abc.txt
drwxr-xr-x 2 durgasoft durgasoft 4096 Dec 5 18:04 Desktop
drwxr-xr-x 2 durgasoft durgasoft 4096 Nov 21 17:06 Documents
drwxr-xr-x 2 durgasoft durgasoft 4096 Nov 21 17:06 Downloads
durgasoft@durgasoft:~/scripts$ GUEST=Dhoni
durgasoft@durgasoft:~/scripts$ echo "Hello $GUEST You are my Hero"
Hello Dhoni You are my Hero
If the variable is readonly then we cannot perform reassignment for that variable.It will
become constant.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
134 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Variable Scopes:
There are 3 scopes available for variables.
1) Session Scope
2) User Scope
3) System Scope
1) Session Scope:
The variables which are declared in the terminal are said to be in session scope.
Once we close the terminal (ie exit session) automatically all variables will be gone.
$ X=10
$ Y=10
2) User Scope:
The variables which are declared inside .bashrc file, are said to be in user scope.
These variables are available for all sessions related to current user. These variables
cannot be accessed by other users.
.bashrac
....
export GUEST=Dhoni
export FRIEND=Sunny
3) System Scope:
If the variable available for all users and for all sessions, such type of variables are said
to be in system scope.
...
export NAME=DURGA
export COURSE=PYTHON
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
135 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Syntax:
$variablename
${variablename}
test.sh
#! /bin/bash
a=10
b=20
COURSE="linux"
ACTION="SLEEP"
echo "Values of a and b are: $a and $b"
echo "My Course is: ${COURSE}"
echo "My Favourite Action: $ACTIONING"
echo "My Favourite Action: ${ACTION}ING"
Output:
Values of a and b are: 10 and 20
My Course is: linux
My Favourite Action:
My Favourite Action: SLEEPING
Ans: B, D
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
136 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: If we use single quotes then variable substitution won't be happend. But we can
use double quotes.
durgasoft@durgasoft:~/scripts$ NAME='durga'
durgasoft@durgasoft:~/scripts$ echo NAME
NAME
durgasoft@durgasoft:~/scripts$ echo $NAME
durga
durgasoft@durgasoft:~/scripts$ echo '$NAME'
$NAME
durgasoft@durgasoft:~/scripts$ echo "$NAME"
durga
Command Substitution:
We can execute command and we can substitute its result based on our requirement by
using command substitution.
Syntax:
Old style: `command ` These are backquotes butnot single quotes
New Style: $(command)
Eg 1:
durgasoft@durgasoft:~/scripts$ echo "Today Date is: `date +%D` "
Today Date is: 12/06/19
durgasoft@durgasoft:~/scripts$ echo "Today Date is: $(date +%D) "
Today Date is: 12/06/19
Eg 2:
durgasoft@durgasoft:~/scripts$ echo "Number of files in Current Working Directory: `ls |
wc -l` "
Number of files in Current Working Directory: 5
durgasoft@durgasoft:~/scripts$ echo "Number of files in Current Working Directory: $(ls |
wc -l) "
Number of files in Current Working Directory: 5
Eg 3:
durgasoft@durgasoft:~/scripts$ echo "The No of Lines in test.sh: `cat test.sh | wc -l` "
The No of Lines in test.sh: 9
durgasoft@durgasoft:~/scripts$ echo "The No of Lines in test.sh: $(wc -l test.sh) "
The No of Lines in test.sh: 9 test.sh
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
137 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg 4:
durgasoft@durgasoft:~/scripts$ echo "My Current Working Directory: `pwd` "
My Current Working Directory: /home/durgasoft/scripts
durgasoft@durgasoft:~/scripts$ echo "My Current Working Directory: $(pwd) "
My Current Working Directory: /home/durgasoft/scripts
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
138 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-28: Command
Line Arguments
The arguments which are passing from the command prompt at the time of executing our
script, are called command line arguments.
The command line arguments are learning, linux, is, very, easy.
Eg: test.sh
#! /bin/bash
echo "Number of arguments: $#"
echo "Script Name: $0"
echo "First argument: $1"
echo "Second argument: $2"
echo "Third argument: $3"
echo "Fourth argument: $4"
echo "Fifth argument: $5"
echo "Total arguments: $*"
Third argument: is
Fourth argument: very
Fifth argument: easy
Total arguments: learning linux is very easy
IFS="-"
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
140 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: The main purpose of command line arguments is to customize behaviour of the
script.
test.sh
#! /bin/bash
l=$(echo -n "DURGA"| wc -c)
echo "The Length of given String: $l"
test.sh
#! /bin/bash
len=$(echo -n "$1"| wc -c)
echo "The Length of given string $1 : $len"
This script will work for any string provided from command prompt.
durgasoft@durgasoft:~/scripts$ test.sh
The Length of given string : 0
durgasoft@durgasoft:~/scripts$ test.sh durgasoft
The Length of given durgasoft : 9
durgasoft@durgasoft:~/scripts$ test.sh adsfkjshfdjkhsfkjhkjsfhk
The Length of given string adsfkjshfdjkhsfkjhkjsfhk : 24
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
141 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
test.sh
#! /bin/bash
echo "Enter A Value:"
read A
durgasoft@durgasoft:~/scripts$ test.sh
Enter A Value:
100
Enter B Value:
200
A Value: 100
B Value: 200
test.sh
#! /bin/bash
echo -n "Enter A Value:"
read A
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
142 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Approach-2
#! /bin/bash
read -p "Enter A Value:" A
read -p "Enter B Value:" B
durgasoft@durgasoft:~/scripts$ test.sh
Enter A Value:100
Enter B Value:200
A Value: 100
B Value: 200
#! /bin/bash
read -p "Enter User Name:" user
read -p "Enter Password:" password
durgasoft@durgasoft:~/scripts$ test.sh
Enter User Name:durga
Enter Password:anushka123
durga thanks for your information
Note:
read -p : Just to display prompt message
read -s : It hides input on screen which is provided by end user.
#! /bin/bash
read -p "Enter User Name:" user
read -s -p "Enter Password:" password
echo
echo "Hello $user , thanks for your information"
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
143 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/scripts$ test.sh
Enter User Name:Durga
Enter Password:
Hello Durga , thanks for your information
durgasoft@durgasoft:~/scripts$ test.sh
Enter Student Name:Durga
Enter Student RollNo:101
Enter Student Age:40
Enter Student Marks:89
Please confirm your details
------------------------------------------------
Student Name: Durga
Student Rollno: 101
Student Age: 40
Student Marks: 89
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
144 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/scripts$ test.sh
Enter Employee Number:100
Enter Employee Name:Sunny
Enter Employee Salary:1000
Enter Employee Address:Mumbai
Below details are saved to the file
100:Sunny:1000:Mumbai
durgasoft@durgasoft:~/scripts$ test.sh
Enter Employee Number:200
Enter Employee Name:Bunny
Enter Employee Salary:2000
Enter Employee Address:Hyderabad
Below details are saved to the file
200:Bunny:2000:Hyderabad
durgasoft@durgasoft:~/scripts$ test.sh
Enter Employee Number:300
Enter Employee Name:Chinny
Enter Employee Salary:3000
Enter Employee Address:Chennai
Below details are saved to the file
300:Chinny:3000:Chennai
durgasoft@durgasoft:~/scripts$
durgasoft@durgasoft:~/scripts$ cat emp.txt
100:Sunny:1000:Mumbai
200:Bunny:2000:Hyderabad
300:Chinny:3000:Chennai
emp.txt
durgasoft@durgasoft:~/scripts$ cat emp.txt
100:Sunny:1000:Mumbai
200:Bunny:2000:Hyderabad
300:Chinny:3000:Chennai
Q4) Write a Script that takes a String from the End User and
Print its Length?
#! /bin/bash
read -p "Enter any string to find length:" str
len=$(echo -n $str | wc -c)
echo "Length of $str : $len"
durgasoft@durgasoft:~/scripts$ test.sh
Enter any string to find length:apple
Length of apple : 5
durgasoft@durgasoft:~/scripts$ test.sh
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
145 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q5) Write a Script to Read File Name from the End User and
display its Content?
#! /bin/bash
Q6) Write a Script to Read File Name from the End User and
Remove Blank Lines Present in that File?
#! /bin/bash
read -p "Enter any File name to remove blank lines:" fname
grep -v "^$" $fname > temp.txt
mv temp.txt $fname
echo "In $fname all blank lines deleted"
Q7) Write a Script to Read File Name from the End User and
Remove Duplicate Lines Present in that File?
#! /bin/bash
read -p "Enter any File name to remove duplicate lines:" fname
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
146 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-30: Operators
1) Arithmetic Operators
+ Addition
- Substraction
* Multiplication (we should use \* as it is wild card character)
/ Division
% Modulo Operator
Logical Operators:
-a Logical AND
-o Logical OR
! Logical Not
Assignment operator =
Note: Except assignment operator, for all operators we have to provide space before and
after operator.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
147 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
#! /bin/bash
read -p "Enter First Number:" a
read -p "Enter First Number:" b
sum=`expr $a + $b`
echo "The Sum: $sum"
sum=$(expr $a + $b)
echo "The Sum: $sum"
let sum=$a+$b
echo "The Sum: $sum"
Here $ symbol is optional. But we should not provide space before and after +.
3) By using (()):
sum=$((a+b))
echo "The Sum: $sum"
sum=$(($a+$b))
echo "The Sum: $sum"
Here space and $ symbol, both are optional.
4) By using []:
sum=$[a+b]
echo "The Sum: $sum"
sum=$[$a+$b]
echo "The Sum: $sum"
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
148 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: All the above 4 approaches will work only for integral arithmetic
(only for integer numbers).
If we want to perform floating point arithmetic then we should use bc command.
bc Command:
bc means binary calculator.
We can start binary calculator by using bc command.
durgasoft@durgasoft:~/scripts$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software
Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10.5+30.6
41.1
10.2^2
104.0
10.5*3.6
37.8
ctrl+d To exit bc
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter First Number:10.5
Enter Second Number:5.3
The Sum:15.8
The Difference: 5.2
The Product: 55.6
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
149 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any 4-digit Integer Number:1234
The Sum of 4 digits : 10
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any 4-digit Integer Number:3456
The Sum of 4 digits : 18
annual_salary=$[salary*12]
bonus=$[annual_salary*25/100]
echo "The Bonus:$bonus"
durgasoft@durgasoft:~/scripts$ test.sh
Enter Employee Monthly Salary:10000
The Bonus:30000
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
150 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1) if Statement:
There are 4 types of if statements
1) simple if
2) if-else
3) nested if
4) ladder if
1) simple if:
if [ condition ]
then
action
fi
Q1) WAS to Read Name from the End User and if Name is
Sunny then Display some Special Message?
#! /bin/bash
if [ $name = "sunny" ]
then
echo "Hello Sunny Very Good Evening"
fi
echo "How are you"
durgasoft@durgasoft:~/scripts$ test.sh
Enter Your Name:durga
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
151 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note:
x=10 Assignment
x = 10 Comparison
2) if -else:
if [ condition]
then
action if condition is true
else
action if condition is false
fi
3) Nested if:
if [ condition ]
then
.........
.........
if [ condition ]
then
.........
.........
else
........
fi
.....
else
......
fi
4) ladder -if:
if [condition]
then
action-1
elif [ condition ]
then
action-2
elif [ condition ]
then
action-3
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
152 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
else
default action
fi
if [ $a -gt $b ]
then
echo "Greater Number is:$a"
else
echo "Greater Number is:$b"
fi
durgasoft@durgasoft:~/scripts$ test.sh
Enter First Number:10
Enter Second Number:20
Greater Number is:20
durgasoft@durgasoft:~/scripts$ test.sh
Enter First Number:20
Enter Second Number:10
Greater Number is:20
durgasoft@durgasoft:~/scripts$ test.sh
Enter First Number:-10
Enter Second Number:-20
Greater Number is:-10
if [ $a -eq $b ]
then
echo "Both Numbers are equal"
elif [ $a -gt $b ]
then
echo "First Number is greater than Second Number"
else
echo "First Number is less than Second Number"
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
153 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
if [ $a -gt $b ]
then
if [ $a -gt $c ]
then
echo "The Greater Number:$a"
else
echo "The Greater Number:$c"
fi
elif [ $b -gt $c ]
then
echo "The Greater Number:$b"
else
echo "The Greater Number:$c"
fi
2nd Way:
#! /bin/bash
if [ $a -gt $b -a $a -gt $c ]
then
echo "The Greater Number: $a"
elif [ $b -gt $c ]
then
echo "The Greater Number: $b"
else
echo "The Greater Number: $c"
fi
WAS to check whether student is pass or fail based on given 3 subjects marks.
In any subject if marks less than 35 then status is fail.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
154 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1st Way:
#! /bin/bash
if [ $a -lt 35 ]
then
echo "Student Failed"
elif [ $b -lt 35 ]
then
echo "Student Failed"
elif [ $c -lt 35 ]
then
echo "Student Failed"
else
echo "Result is Pass"
fi
2nd Way:
#! /bin/bash
if [ $brand = "KF" ]
then
echo "It is Childrens Brand"
then
echo "It is not that much Kick"
durgasoft@durgasoft:~/scripts$ ./test.sh
Enter Your Favourite Brand:KF
It is Childrens Brand
durgasoft@durgasoft:~/scripts$ ./test.sh
Enter Your Favourite Brand:KO
It is not that much Kick
durgasoft@durgasoft:~/scripts$ ./test.sh
Enter Your Favourite Brand:RC
It is too light
durgasoft@durgasoft:~/scripts$ ./test.sh
Enter Your Favourite Brand:FO
Buy One Get One FREE
durgasoft@durgasoft:~/scripts$
durgasoft@durgasoft:~/scripts$ ./test.sh
Enter Your Favourite Brand:KALYANI
Other Brands are not recommended
durgasoft@durgasoft:~/scripts$ rm sdfjkslajfdksajfjdsakjfdksajfkd
rm: cannot remove 'sdfjkslajfdksajfjdsakjfdksajfkd': No such file or
directory
durgasoft@durgasoft:~/scripts$ echo "$?"
1
exit Command:
In the script to stop execution in the middle, we can use exit command.
Syntax:
exit status_code
The allowed values for status_code are 0 to 255.
256 0
257 1
258 2
259 3
....
Q5) Write a Script that takes 2 Integer Numbers as Command Line Arguments
and Prints Sum
If Number of Arguments is not 2, then we have to get Message saying
"You should provide only 2 Arguments"
If the Arguments are not Integer Numbers then we have to get Message
saying "You should provide Integer Numbers only"
test.sh
#! /bin/bash
if [ $# -ne 2 ]
then
echo "You Should provide exactly two arguments"
exit 1
fi
x=$1
y=$2
sum=`expr $x + $y `
if [ $? -ne 0 ]
then
echo "You should provide integer numbers only"
exit 2
else
echo "The Sum:$sum"
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
157 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Output:
durgasoft@durgasoft:~/scripts$ test.sh 10 20
The Sum:30
durgasoft@durgasoft:~/scripts$ test.sh
You Should provide exactly two arguments
durgasoft@durgasoft:~/scripts$ test.sh 10
You Should provide exactly two arguments
durgasoft@durgasoft:~/scripts$ test.sh 10 20 30
You Should provide exactly two arguments
durgasoft@durgasoft:~/scripts$ test.sh 10 durga
expr: non-integer argument
You should provide integer numbers only
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:10
10 is +ve number
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:-10
-10 is -ve number
Note: If we want to take then in the same line then we should use ;
if [ $n -gt 0 ]; then
The advantage is we can reduce the number of lines.
else
echo "$n is odd number"
fi
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:10
10 is even number
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:15
15 is odd number
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:123
123 is 3-dgit number
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:45
45 is not 3-digit number
durgasoft@durgasoft:~/scripts$ test.sh
Enter integer number to check:1234
1234 is not 3-digit number
if [ -e $fname ]
then
echo "$fname exists"
else
echo "$fname not exists"
fi
if [ -e $fname ]; then
if [ -f $fname ]; then
echo "It is regular file"
elif [ -d $fname ]; then
echo "It is Directory file"
else
echo "It is special file"
fi
else
echo "$fname does not exist"
fi
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter File Name to test:a.txt
It is regular file
durgasoft@durgasoft:~/scripts$ test.sh
Enter File Name to test:dir1
It is Directory file
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
160 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
durgasoft@durgasoft:~/scripts$ test.sh
Enter File Name to test:dddddd
dddddd does not exist
durgasoft@durgasoft:~/scripts$ test.sh
Enter File Name to test:/bin
It is Directory file
durgasoft@durgasoft:~/scripts$ test.sh
Enter File Name to test:/dev/vcsa3
It is special file
if [ -e $fname ]; then
if [ -f $fname ]; then
if [ -r $fname ]; then
cat $fname
else
echo "User not having Read permission"
fi
else
echo "It is not a regular file"
fi
else
echo "$fname does not exist"
fi
Q9) Write a Script that Reads File Name and Check whether
it is Empty File OR not?
#! /bin/bash
if [ -e $fname ]; then
if [ -f $fname ]; then
if [ -s $fname ]; then
echo "$fname is not empty file"
else
echo "$fname is empty file"
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
161 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
else
echo "It is not a regular file"
fi
else
echo "$fname does not exist"
fi
Note:
-z is string comparison option.
returns True if the string is empty.
READ=NO
WRITE=NO
EXECUTE=NO
if [ -r $fname ]; then
READ=YES
fi
if [ -w $fname ]; then
WRITE=YES
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
162 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
if [ -x $fname ]; then
EXECUTE=YES
fi
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter First File Name: a.txt
Q12) Write a Scirpt that Reads File Name and Remove the
specified File?
#! /bin/bash
Mini Application:
Copy all files and directories present in the first directory to the second directory. We
should create compressed tar file and have to move that tar file.
After moving tar file to the second directory, extract all files and directories and remove
that tar file.
copy /home/durgasoft/x /home/durgasoft/y
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
163 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Tests to Perform:
1) The number of command line arguments should be 2
2) The source and destination directories should be available already
3) The source and destination arguments should be directories
4) The user should has read and execute permissions on source directory
5) The user should has write and execute permissions on destination directory
6) All error messages should be send to error file and the file name should contain
timestamp.
7) All intermediate steps should be displayed to the terminal.
Note:
elif [ $str1 \< $str2 ]; then
If we are not using \ symbol then < acts as input redirection operator. To consider < as
symbol only we should use \.
durgasoft@durgasoft:~/scripts$ test.sh
Enter First String:Durga
Enter Second String:Durga
Both strings are equal
durgasoft@durgasoft:~/scripts$ test.sh
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
164 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q13) Write a Script that Checks whether Login User is Root OR not. If Login
User is Root then Display 1st 5 Current Running Processes Information
#! /bin/bash
user=$(whoami)
durgasoft@durgasoft:~/scripts$ test.sh
Current user not root user and hence exiting
durgasoft@durgasoft:~/scripts$ sudo -i
[sudo] password for durgasoft:
root@durgasoft:~# whoami
root
root@durgasoft:~# test.sh
test.sh: command not found
root@durgasoft:~# pwd
/root
root@durgasoft:~# /home/durgasoft/scripts/test.sh
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
165 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
if [ -z $str ]; then
echo "Provided input string is empty string"
else
echo "Provided input string is not empty string"
echo "Its length is : $( echo -n $str | wc -c)"
fi
2) case Statement:
If multiple options are available then it is not recommended to use nested if-else
statements. It increases length of the code and reduces readability.
Syntax:
case $variable in
option1 )
action-1
;;
option2 )
action-2
;;
option3 )
action-3
;;
*)
default action
;;
esac
Note:
1) space is optional while defining options.
2) ;; can be used to come out of case statement.
3) ;; is mandatory for all options except for default option.
4) If we take default option at the beginning, then for any input the same default option
will be executed.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
166 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg 1: Write a script to read a number from 0 to 9 and print equivalent English word?
#! /bin/bash
case $n in
0) echo "ZERO"
;;
1) echo "ONE"
;;
2) echo "TWO"
;;
3) echo "THREE"
;;
4) echo "FOUR"
;;
5) echo "FIVE"
;;
6) echo "SIX"
;;
7) echo "SEVEN"
;;
8) echo "EIGHT"
;;
9) echo "NINE"
;;
*) echo "Please enter a digit from 0 to 9 only"
esac
case $brand in
"KF")
echo "It is childrens brand"
;;
"KO")
echo "It is not that much kick"
;;
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
167 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
"RC")
echo "It is too light"
;;
"FO")
echo "Buy one get one FREE"
;;
*)
echo "Other brands are not recommended"
esac
Q16) Write a Script that Accepts a Single Character and Check whether the
given Character is Alphabet OR Digit OR Special Character?
#! /bin/bash
case $ch in
[a-zA-Z])
echo "It is an Alphabet symbol"
;;
[0-9])
echo "It is a Digit"
;;
[^a-zA-Z0-9])
echo "It is a Special Symbol"
;;
*)
echo "Enter only one character"
esac
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: a
It is an Alphabet symbol
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: 8
It is a Digit
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: $
It is a Special Symbol
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: durga
Enter only one character
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
168 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q17) Write a Script that Accepts a Single Character and Checks whether it is
Digit OR Special Character OR Vowel OR Consonent?
#! /bin/bash
case $ch in
[^a-zA-Z0-9])
echo "It is a Special Character"
;;
[0-9])
echo "It is a Digit"
;;
[aeiouAEIOU])
echo "It is a Vowel"
;;
[^aeiouAEIOU])
echo "It is a Consonent"
;;
*)
echo "Enter only one character"
esac
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: a
It is a Vowel
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: s
It is a Consonent
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: 7
It is a Digit
durgasoft@durgasoft:~/scripts$ test.sh
Enter Any Character to check: $
It is a Special Character
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
169 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
#! /bin/bash
echo "A Display Content"
echo "B Append Content"
echo "C Overwrite Content"
echo "D Delete Content"
read -p "Choose Your Option A|B|C|D: " option
case $option in
A)
if [ ! -s "abc.txt" ]; then
echo "It is an empty file"
else
#! /bin/bash
case $option in
1)
echo "$n1 + $n2 = $((n1+n2))"
;;
2)
echo "$n1 - $n2 = $((n1-n2))"
;;
3)
echo "$n1 * $n2 = $((n1*n2))"
;;
4)
echo "$n1 / $n2 = $((n1/n2))"
;;
*)
echo "Choose only 1|2|3|4. Execute Again"
esac
Iterative Statements:
If we want to execute a group of commands multiple times then we should go for iterative
statements.
1) while loop
2) until loop
3) for loop
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
171 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
1) while Loop:
If we don't know the number of iterations in advance, then we should go for while
loop.
Syntax:
while [ condition ]
do
body
done
As long as condition is true, then body will be executed. Once condition fails then only
loop will be terminated.
i=1
while [ $i -le 10 ]
do
echo $i
let i++
done
while [ $i -le $n ]
do
echo $i
sleep 2
let i++
done
Note: If we don't want to perform any operation for a particular amount of time (i.e just
pausing is required) then we should go for sleep command. The argument to the sleep
command is seconds.
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
172 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Eg:
sleep 2
sleep 3
sleep 0.5
i=1
sum=0
while [ $i -le $n ]
do
let sum=sum+i
let i++
done
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter n value:3
The Sum of first 3 numbers: 6
durgasoft@durgasoft:~/scripts$ test.sh
Enter n value:10
The Sum of first 10 numbers: 55
durgasoft@durgasoft:~/scripts$ test.sh
Enter n value:12345
The Sum of first 12345 numbers: 76205685
while [ true ]
do
clear
printf "\n\n\n\n\n\n\t\t\t\t$(date +%H:%M:%S)"
sleep 1
done
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
173 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Note: To use escape characters like \n and \t, we should not use echo and we should use
printf command.
Note: true and false are keywords which represents boolean values.
break Statement:
Based on some condition, if we want to break loop execution (i.e to come out of loop)
then we should go for break statement.
Eg 1:
#! /bin/bash
i=1
while [ $i -le 10 ]
do
if [ $i -eq 5 ]; then
break
fi
echo $i
let i++
done
Output:
1
2
3
4
Eg 2:
#! /bin/bash
while [ true ]
do
clear
printf "\n\n\n\n\n\n\t\t\t\t$(date +%H:%M:%S)"
sleep 1
h=$(date +%H)
m=$(date +%M)
if [ $h -eq 20 -a $m -eq 35 ]; then
break
fi
done
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
174 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
continue Statement:
We can use continue statement to skip current iteration and continue for the next
iteration.
Eg:
#! /bin/bash
i=0
while [ $i -lt 10 ]
do
let i++
if [ $[i%2] -eq 0 ]; then
continue
fi
echo $i
done
Output:
1
3
5
7
9
while [ true ]
do
read -p "Enter File Name to Display content: " fname
# Checking whether the file exists or not and whether regular file or not
if [ -f $fname ]; then
echo "The content of $fname :"
echo "----------------------"
cat $fname
else
echo "$fname does not exist"
fi
read -p "Do you want to display content of another file [Yes|No]:" option
case $option in
[yY]|[Yy][eE][sS])
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
175 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
continue
;;
[nN]|[nN][oO])
break
;;
esac
done
echo "Thanks for using application"
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter File Name to Display content: abc.txt
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
176 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Write a Script that Reads a String as Input and find its Reverse?
Write a Script that performs Reverse of given String?
#! /bin/bash
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Enter any string to find reverse: durga
The Original String: durga
The Reversed String: agrud
durgasoft@durgasoft:~/scripts$ test.sh
Enter any string to find reverse: abc
The Original String: abc
The Reversed String: cba
durgasoft@durgasoft:~/scripts$ test.sh
Enter any string to find reverse: durgasoft
The Original String: durgasoft
The Reversed String: tfosagrud
durgasoft@durgasoft:~/scripts$
Eg:
#! /bin/bash
while [ true ]
do
clear
tput cup 7 25
echo "WELCOME TO DURGASOFT"
sleep 2
clear
tput cup 7 25
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
177 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
while [ true ]
do
read -p "Employee Number: " eno
read -p "Employee Name: " ename
read -p "Employee Salary: " esal
read -p "Employee Address: " eaddr
echo "$eno:$ename:$esal:$eaddr" >> emp.txt
echo "Employee Record Inserted Successfully"
read -p "Do you want to insert one more record [Yes|No]: " option
case $option in
[yY]|[Yy][eE][sS])
continue
;;
[nN]|[nN][oO])
break
;;
esac
done
echo "Open emp.txt to see all employees information"
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Employee Number: 100
Employee Name: Sunny
Employee Salary: 1000
Employee Address: Hyderabad
Employee Record Inserted Successfully
Do you want to insert one more record [Yes|No]: y
Employee Number: 200
Employee Name: Bunny
Employee Salary: 2000
Employee Address: Mumbai
Employee Record Inserted Successfully
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
178 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Syntax -1: To read data from the file by using while loop
cat emp.txt |
while read line
do
do something with that line
done
Syntax -2: To read data from the file by using while loop
while read line
do
do something with that line
done < emp.txt
test.sh
#! /bin/bash
fname=$1
if [ ! -f $fname ]; then
echo "Please provide already existing regular file only"
exit 1
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
179 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
count=1
while read line
do
echo " $count $line"
let count++
done < $fname
Output
durgasoft@durgasoft:~/scripts$ test.sh emp.txt
1 100:Sunny:1000:Hyderabad
2 200:Bunny:2000:Mumbai
3 300:Chinny:3000:Hyderabad
4 400:Vinny:4000:Chennai
durgasoft@durgasoft:~/scripts$ test.sh abcd.txt
Please provide already existing regular file only
2) until Loop:
It is opposite to while loop.
Syntax:
until [ condition ]
do
body
done
The body will be executed as long as condition returns false. Once condition returns true,
then loop will be terminated.
durgasoft@durgasoft:~/scripts$ test.sh
1
2
3
4
5
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
180 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
3) for Loop:
If we want to perform some action for every item in the given list, then we should go for
for loop. It is similar to Java's for-each loop.
Syntax:
for variable in item1 item2 item3... itemN
do
action
done
for i in 1 2 3 4 5
do
echo "Current Number: $i"
done
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Current Number: 1
Current Number: 2
Current Number: 3
Current Number: 4
Current Number: 5
Eg 2:
#! /bin/bash
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Course Name: java
Course Name: unix
Course Name: python
Course Name: testing
Course Name: datascience
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
181 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Q8) Write a Script that Display Numbers from 1 to 100, which are
divisible by 10.
#! /bin/bash
count=0
for num in {1..100}
do
if [ $[ num%10 ] -eq 0 ]; then
echo "$num"
let count++
fi
done
echo "The number of values: $count"
Output:
durgasoft@durgasoft:~/scripts$ test.sh
10
20
30
40
50
60
70
80
90
100
The number of values: 10
for name in *
do
if [ -f $name ]; then
echo $name
fi
done
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
182 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
if [ $# -ne 0 ]; then
count=1
for arg in $@
do
echo "Command Line Argument - $count: $arg"
let count++
done
else
echo "Command line arguments are not passed"
fi
Output:
durgasoft@durgasoft:~/scripts$ test.sh
Command line arguments are not passed
durgasoft@durgasoft:~/scripts$ test.sh 10 20 30 40
Command Line Argument - 1: 10
Command Line Argument - 2: 20
Command Line Argument - 3: 30
Command Line Argument - 4: 40
durgasoft@durgasoft:~/scripts$ test.sh learning linux is very easy
Command Line Argument - 1: learning
Command Line Argument - 2: linux
Command Line Argument - 3: is
Command Line Argument - 4: very
Command Line Argument - 5: easy
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
183 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Case Study:
emp.txt:
100:sunny:1000:Hyderabad
200:bunny:2000:Chennai
300:chinny:3000:Hyderabad
400:vinny:4000:Delhi
500:pinny:5000:Hyderabad
if [ $# -ne 0 ]; then
for fname in $@
do
if [ -f $fname ]; then
echo "$fname content:"
echo "====================="
cat $fname
else
echo "$fname does not exist or it is not a regular file"
fi
done
else
echo "Please pass atleast one file name"
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
185 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
if [ $# -ne 0 ]; then
for fname in $@
do
if [ -f $fname ]; then
cat $fname >> result.txt
else
echo "$fname does not exist or it is not a regular file"
fi
done
else
echo "Please pass atleast one file name"
fi
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
186 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Output:
0
1
2
3
4
durga@durga-VirtualBox:~/scripts$ test.sh
Enter n value:9
9*1=9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
9 * 10 = 90
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
187 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
#! /bin/bash
echo "Welcome to DURGA HOTEL"
echo
amount=0
while [ true ]
do
echo "Menu Items:"
echo "......................"
echo "A --->Vadapov (Each Plate Rs 30 /-)"
echo "B --->Dosa (Each Plate Rs 50 /-)"
echo "C --->Poori (Each Plate Rs 40 /-)"
echo "D --->Idli (Each Plate Rs 25 /-)"
read -p "Choose Your Required Item A|B|C|D:" item
case $item in
A)
read -p "Enter the number of plates of Vadapov, you required:" quantity
amount=$[amount+quantity*30]
;;
B)
read -p "Enter the number of plates of Dosa, you required:" quantity
amount=$[amount+quantity*50]
;;
C)
read -p "Enter the number of plates of Poori, you required:" quantity
amount=$[amount+quantity*40]
;;
D)
read -p "Enter the number of plates of Idli, you required:" quantity
amount=$[amount+quantity*25]
;;
*)
echo "You entered invalid option. Choose Again"
continue
esac
read -p "Do you want to order any other item[Yes|No]:" option
case $option in
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
188 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
[Yy]|[Yy][Ee][Ss])
continue
;;
[Nn]|[Nn][Oo])
break
;;
esac
done
echo
echo "Your Total Bill Amount: Rs $amount/-"
echo "Thanks for visiting DURGA HOTEL"
durga@durga-VirtualBox:~/scripts$ test.sh
Welcome to DURGA HOTEL
Menu Items:
……….…………
A Vadapov (Each Plate Rs 30 /-)
B Dosa (Each Plate Rs 50 /-)
C Poori (Each Plate Rs 40 /-)
D Idli (Each Plate Rs 25 /-)
Choose Your Required Item A|B|C|D:D
Enter the number of plates of Idli, you required:4
Do you want to order any other item[Yes|No]:yes
Menu Items:
……….…………
A Vadapov (Each Plate Rs 30 /-)
B Dosa (Each Plate Rs 50 /-)
C Poori (Each Plate Rs 40 /-)
D Idli (Each Plate Rs 25 /-)
Choose Your Required Item A|B|C|D:C
Enter the number of plates of Poori, you required:3
Do you want to order any other item[Yes|No]:Yes
Menu Items:
……….…………
A Vadapov (Each Plate Rs 30 /-)
B Dosa (Each Plate Rs 50 /-)
C Poori (Each Plate Rs 40 /-)
D Idli (Each Plate Rs 25 /-)
Choose Your Required Item A|B|C|D:B
Enter the number of plates of Dosa, you required:2
Do you want to order any other item[Yes|No]:Yes
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
189 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Menu Items:
……….…………
A Vadapov (Each Plate Rs 30 /-)
B Dosa (Each Plate Rs 50 /-)
C Poori (Each Plate Rs 40 /-)
D Idli (Each Plate Rs 25 /-)
Choose Your Required Item A|B|C|D:A
Enter the number of plates of Vadapov, you required:1
Do you want to order any other item[Yes|No]:No
2 1, 2
3 1, 3
5 1, 5
#! /bin/bash
read -p "Enter Any Number to test whether it is prime or not:" n
if [ $n -le 1 ]; then
echo "$n is not a PRIME number"
exit 1
fi
for ((i=2;i<=n/2;i++))
do
if [ $[n%i] -eq 0 ]; then
echo "$n is not PRIME number"
exit 1
fi
done
echo "$n is a PRIME number"
durga@durga-VirtualBox:~/scripts$ test.sh
Enter Any Number to test whether it is prime or not:23
23 is PRIME number
durga@durga-VirtualBox:~/scripts$ test.sh
Enter Any Number to test whether it is prime or not:29
29 is PRIME number
durga@durga-VirtualBox:~/scripts$ test.sh
Enter Any Number to test whether it is prime or not:35
35 is not PRIME number
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
190 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Topic-32: Arrays
If we want to represent a group of values with a single name then we should go for arrays
concept.
courses[10]=DataScience
courses[20]=Devops
Demo Script:
#! /bin/bash
courses[0]=Java
courses[1]=Python
courses[2]=Linux
courses[3]=Django
courses[10]=DataScience
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
191 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
courses[20]=Devops
echo "First Element : ${courses[0]}"
echo "Second Element : ${courses[1]}"
echo "All Elements with @ : ${courses[@]}"
echo "All elements with * : ${courses[*]}"
echo "The indices where elements are available : ${!courses[@]}"
echo "The total number of elements : ${#courses[@]}"
echo "The length of first element : ${#courses[0]}"
Output:
durgasoft@durgasoft:~/scripts$ test.sh
First Element : Java
Second Element : Python
All Elements with @ : Java Python Linux Django DataScience Devops
All elements with * : Java Python Linux Django DataScience Devops
The indices where elements are available : 0 1 2 3 10 20
The total number of elements : 6
The length of first element : 4
Q1) Write a Script to Create an Array with some Elements and Print all
Elements by using while Loop, for Loop and advanced for Loop?
#! /bin/bash
declare -a fruits
fruits=("Apple" "Orange" "Banana" "Mango")
size=${#fruits[@]}
i=0
do
echo ${fruits[$i]}
done
Output:
durga@durga-VirtualBox:~/scripts$ test.sh
All elements by using while loop:
Apple
Orange
Banana
Mango
All elements by using for loop:
Apple
Orange
Banana
Mango
All elements by using advanced for loop:
Apple
Orange
Banana
Mango
Note:
1) If we create an array with elements directly
fruits=("Apple" "Orange" "Banana" "Mango")
then the indices will be 0,1,2,3 etc
Q2) Write a Script for accessing Array Elements by using for Loop if
Indices are Random?
#! /bin/bash
declare -a fruits
fruits[10]="Apple"
fruits[20]="Banana"
fruits[30]="Orange"
fruits[40]="Mango"
echo $fruit
done
echo
echo "Accessing based on Index:"
for index in ${!fruits[@]}
do
echo ${fruits[$index]}
done
Output:
durga@durga-VirtualBox:~/scripts$ test.sh
Accessing based on Values:
Apple
Banana
Orange
Mango
Eg:
#! /bin/bash
declare -a fruits
fruits[10]="Apple"
fruits[20]="Banana"
fruits[30]="Orange"
fruits[40]="Mango"
Output:
durga@durga-VirtualBox:~/scripts$ test.sh
All Array Elements Before Removal: Apple Banana Orange Mango
All Array Elements After Removal: Apple Orange
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
194 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
for ((i=0,j=1;i<n;i++))
do
read -p "Enter The Number-$[j++]:" NUM[${i}]
done
Output:
durga@durga-VirtualBox:~/scripts$ test.sh
Enter The Number Of values:3
Enter The Number-1:10
Enter The Number-2:20
Enter The Number-3:30
Q5) Write a Script to Read n Numbers and Store inside Array. Print
the Sum of Even Numbers and Odd Numbers separately?
#! /bin/bash
read -p "Enter Number of Values:" n
for((i=0,j=1;i<n;i++))
do
read -p "Enter The Number-$[j++]:" NUM[$i]
done
esum=0
osum=0
for val in ${NUM[@]}
do
if [ $[val%2] -eq 0 ]; then
let esum=esum+val
else
let osum=osum+val
fi
done
echo "The Sum of Even Numbers: $esum"
echo "The Sum of Odd Numbers: $osum"
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
195 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Output:
durga@durga-VirtualBox:~/scripts$ test.sh
Enter Number of Values:5
Enter The Number-1:10
Enter The Number-2:12
Enter The Number-3:13
Enter The Number-4:15
Enter The Number-5:20
The Sum of Even Numbers: 42
The Sum of Odd Numbers: 28
Q6) Write a Script to Store all .txt File Names Present in Current Working
Directory in to an Array and Print Permissions of every File
#! /bin/bash
files=($(ls *.txt))
for fname in ${files[@]}
do
echo -ne "$fname:\t"
if [ -r $fname ]; then
echo -ne "READ(Y)\t"
else
echo -ne "READ(N)\t"
fi
if [ -w $fname ]; then
echo -ne "WRITE(Y)\t"
else
echo -ne "WRITE(N)\t"
fi
if [ -x $fname ]; then
echo "EXECUTE(Y)"
else
echo "EXECUTE(N)"
fi
done
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
196 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]
UNIX/LINUX
Output:
durga@durga-VirtualBox:~/scripts$ test.sh
abcd.txt: READ(Y) WRITE(Y) EXECUTE(N)
abc.txt: READ(Y) WRITE(Y) EXECUTE(N)
a.txt: READ(Y) WRITE(Y) EXECUTE(N)
b.txt: READ(Y) WRITE(Y) EXECUTE(N)
c.txt: READ(Y) WRITE(Y) EXECUTE(N)
emp.txt: READ(Y) WRITE(Y) EXECUTE(N)
hyd.txt: READ(Y) WRITE(Y) EXECUTE(N)
output.txt: READ(Y) WRITE(Y) EXECUTE(N)
result.txt: READ(Y) WRITE(Y) EXECUTE(N)
z.txt: READ(N) WRITE(N) EXECUTE(N)
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
197 88 85 25 26 27, 72 07 21 24 27/28 | www.durgasoftonline.com
Maii: [email protected]