ULP Lab File
ULP Lab File
-1
Problem Statement:
Familiarize with Unix/Linux Log In/log Out and various other commands& vi editor.
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Commands:
1. $login:
Login: piet
Password: 123
3. $passwd:
Changing password for current user
(Current) Linux passwd-123
New passwd:456
4. $date: Display current system date and [Link] Sep 21 17:57:15 EDT 2016
7. $ who: The information of users who is currently logged into the [Link] :0 2015-08-
25 17:46
8. $ who am i:
piet pts/2 2015-08-25 17:46
9. $ who -Hu:
Name Line Time IDLE PID COMMENT piet pts/1 2016-08-
25 17:46 3456(.00)
1 |P a g e
10. $ date:
$ date “+ my birthday is %d %b %Y”
My birthday is 23 sep 16
Year-
Y- full year 2016 y-
Abb year 16 Month-
B-full month m-
numeric month day
of month-d
TIME- Hours-H
Minute-M Second-s
11. $ echo:
-Display the message on the terminal screen
-it does not recognize the blank space
-without an argument pull a blank line
12. $ tty:
Linux treats everything as files, even the terminal connected are represented as files.
$tty
/dev/pts/1
$
Here terminal filename is 1
13. $ tput:
Command is used to control the cursor on the screen.
$ tput clear-clear the screen
$ tput cup 10 5 –cup is an argument along with 10 th row and 5th
column $ tput smso-start bold sequence $ tput rmso –start normal
sequence
14. $ uname:
(i) $ uname
Linux
$
(ii) $ uname – r
2.4.18
This reption gives the version number of machine.
(iii) $ uname –m i
686
This gives the detects of machine (iv) $
uname -a
Gives all detail of the system
2 |P a g e
15. $ bc:
-It is for calculator and small language for writing numerical programs. -After
using this command use CTRL+D for exit.
$ bc
60+6
66
[Ctrl+D]
$
16. $script:
This command is used to record an interactive session.
$script
Script started, file is typescript
$ exit
Script done, file is typescript 17.
$ more typescript:
With this command we can see the recorded session 18.
$ man:
It gives format and manual page of command. It includes NAME, DESCRIPTION and
SYNOPSIS.
$ man command_name 19.
$stty:
Display the setting of terminal
$ stty –a - print all current setting in human re adable form
20. $ ls- List the directories and files$ ls [option]….[file]…..
$ ls –a – shows all the files
$ ls –A- show almost all file
$ ls –m- comma seperates list of enteries
$ ls –r- reverse order while sorting
$ ls –s- show file by size
$ ls –t- sort by modification time
21. $ cd -used for change directory$ cd dirname
For eg: $pwd
/home/cloudera $ cd
Desktop $pwd
/home/cloudera/Deskto
p
22. $ pwd
-It gives presnt working directory For
eg:
$pwd
/home/cloudera
23. $ mkdir
-New directories can be created by mkdir command For
eg:
$ mkdir abhi: create directory abhi
$ mkdir a a/b: make a directory with a name and then sub directory b under the parent a 24.
$ rmdir
3 |P a g e
-it removes directory.
-directory must be empty
$ rm filename
25. $ mv
-Moving or renaming filename and directory
$ mv old file name new file name
26. $ cat
-It is used to create a new file, see content of a file and contents to the existing file.
$ cat filename For eg.
$ cat helloworld.c (i)
$ cat > filename
………. type…character
…….
……………….
- to create a filename
29. $ cp
Copy the content of old file to new file if new file does not exist then it first create destination
new file first and then add content of old file to new file.
$cp old_file new_file
30. To view long files
-pg, more and less are basic command to see files having more contents.
-head and tail to see beginning and ending contents of a file
(i)$ pg filename-display the content of file name
$pg -10-display maximum 10 lines for each window
$pg+10-start to display lines from line no.10
(ii)$ more filename
–show in %
-press spacde bar next window
-Ctrl+D to move forward one screen
-Ctrl+B to move backword on screen
(iii)$ head
-display first few line of one and more files
$head file1 file2 file3
= =>file1<<= =
abcd
= =>file2<<= =
abc
= =>file3<<= =
Abcd
$head sec- it display first 10 lines of sec filename
$head -15 sec- display 15 files
(iv)$ tail
$tail filename1..2
-Display last few lines of one or more files
$tail sec
-it display last 10 lines of sec filename
31. $wc:- $wc filename
32. $cmp
4 |P a g e
To compare files we use cmp command. If the contents of two or more files are same and we
want to delete files that are identical then use cmp command.
If files are differ then it will give msg like file1 file 2 differ: byte1, line1
Syntax: $ cmp file1 file2
33. $comm
$comm file1 file2 -common data in two or more files
34. $diff-
$diff file1 file2–difference betw een files and it also tells the changes you have to make to make
two files identical.
The vi editor is the most popular editor in Linux. The current version is really "vim", but to invoke
it simply type "vi". The text format that vi uses is the plainest elementary text format that exists,
the ASCII format. But files created by vi can be run through other programs that convert the files
to other formats, if desired. In Linux and other Unix clone operating systems, the operating system
and the editor do not care whether or not file names have suffixes or extensions.
Open a terminal window in your Linux system and click on it to make sure it is active. You will
do all your work in the terminal window. If you are not already familiar with how to open a
terminal window, find what directory you are in, list the files in a directory, create a directory,
move files, copy files, rename files, delete files, execute programs, add missing commands and
Linux command line operations in a terminal window you should first read my article how to use
Linux terminal.
To edit an existing file named "xyz", or create a new file named "xyz", type "vi xyz". When in vi,
there are two major modes, the input mode and the edit mode. In the input mode, anything you
type goes into the file. In the edit mode you can move around the file, copy, delete etc. Hit the
"Esc" key to get from the input mode to the edit mode. When in the edit mode the mouse is not
used to move the cursor, keyboard commands are used. The arrow keys move the cursor up,
down, right, left. The spacebar moves the cursor to the right. "$" moves the cursor to the end of
the present line. The "enter" key moves the cursor to the beginning of the next line. "237" then
the "enter" key will move ahead 237 lines in the file, unless there are less than 237 lines in the
file, in which case the cursor will not move. Type "1G" to jump to the top of the file, "G" to move
to the end of the file.
vi name_of_the_file
Once the file is open, you can move around by using cursors or the keys h, j, k and l (in case the
keyboard does not have any arrow cursors).
When the cursor is moved to a particular letter in a word in the file, press "a" to enter the insert
mode after that letter, press "i" to enter the insert mode just before that letter. Type what you want
in the insert mode then hit the "Esc" key to leave the insert mode and get back to the edit mode.
5 |P a g e
Modes:-
1. Command mode
2. Insert mode
$ Vi [Link]
quite : q!
write : w!
reload : e!
k up one line
6 |P a g e
Editing the text
7 |P a g e
Practical No.-2
Problem Statement:
Develop simple shell programs using Bash or any other shell in Linux.
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Commands:
You can write a shell scripts by text editor like vi or by using cat command
1) Write a program in shell to display output of who, cal and pwd command
$ cat > myprog #File name is myprog
who
cal
pwd
ctrl+d
$
Execute file:
8 |P a g e
In this method, we have to first make the file executable by giving it execution permission
using chmod command. Because initially owner of the file does not have the executable
permission.
$ chmod u+x [Link]
To run the program we use the following command. $
./myprog
You will get an error message “myprog” execution permission denied”. This is because when
a new file is created , it is created with read and write permission of owner not execute
permission . To solve this problem use chmod command to make it executable.
then
$ ./myprog
for a in 1 2 3 4 5 do
done
ctrl+d
Output :-
welcome 1 times
welcome 2 times
welcome 3 times
$ ./explicit_list.sh
9 |P a g e
2) You can make program in vi editor also.
$ vi [Link]
for a in
{1…5} do
$ ./[Link]
Output :-
welcome 1 times
welcome 2 times
welcome 3 times
welcome 4 times
welcome 5 times
3) $ vi setting_step.sh
for a in (1..10..3) do
Output:-
welcome 1 times
welcome 4 times
welcome 7 times
10 |P a g e
welcome 10 times
echo $i
i=$(($i+1))
done
11 |P a g e
5)Write a shell script to print first 10 natural numbers with a
step of 2.
echo $i
i=$(($i+1))
done
Code:
#!/bin/bash
#shell script to add two numbers #using
command line arguments
#$1 refers to the first argument
#$2 refers the second argument and so on
sum=$(($1 + $2)) echo "Sum = $sum"
Output:
12 |P a g e
8)Positive or Negative - Shell Script
Code:
#!/bin/bash echo
"Enter a Number" read
num
if [ $num -lt0 ]
then echo
"Negative" elif [
$num -gt0 ] then
echo "Positive" else echo "Neither
Positive Nor Negative" fi
Output:
Code:
#!/bin/bash echo
"Enter Num1" read
num1 echo "Enter
Num2" read num2
echo "Enter Num3"
read num3
if [ $num1 -gt $num2 ]&& [ $num1 -gt $num3 ]
then echo $num1
elif [ $num2 -gt $num1 ]&& [ $num2 -gt $num3 ]
then echo $num2 else echo $num3
fi
Output:
13 |P a g e
9) Shell Script to print numbers 1 to 10 using
(i) while loop
Code: Output:
Code: Output:
Code:
#!/bin/bash echo
"Enter a number" read
num sum=0
while [ $num -gt0 ] do mod=`expr $num % 10` #It
will split each digits sum=`expr $sum + $mod`
14 |P a g e
#Add each digit to sum num=`expr $num / 10`
#divide num by 10.
done echo
$sum
Output:
Code:
#!/bin/bash echo
"Enter a number" read
num fact=1 while [
$num -gt1 ]
do fact=$((fact *num)) #fact = fact *
num num=$((num-1)) #num = num
- 1 done echo $fact Output:
15 |P a g e
12) Shell script to add and access array elements
Code:
#!/bin/bash arr=(10
20 30 40 50) sum=0
foriin ${arr[@]} do
sum=`expr $sum + $i`
done echo $sum
Output:
Code:
#!/bin/bash
functionadd() {
sum=$(($1 + $2))
echo "Sum = $sum"
} a=10
b=20
#call the add function and pass the values
add $a $b Output:
Code:
16 |P a g e
fi
Output:
17 |P a g e
Practical No.-3
Problem Statement:
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Commands:
GREP:-GREP stands for global regular expressions print. It is a filter which is capable to
receiving its input from standard input and sending its output to standard output.
1. GREP
2. EGERP- Extended GREP
3. FGREP- Fixed GREP
1. GREP:- This command is used to search or extract lines or records from an input [Link]
means entire file is searched for specified patterns
OUTPUT:
18 |P a g e
OUTPUT:
RK bakshi
[Link] options:-
4.1 Inverse option(-v) :- It will print those lines that do not contain specified patterns.
OUTPUT:
Rajender
Pawan
Mukesh
Anil
4.2 C ignore option(-i) :- GREP distinguish between uppercase and lowercase. With i optionit
will print all patterns without considering the case.
OUTPUT:
Dp gupta
4.3 Filename option(-l) :- Print the filename in which specified pattern is present.
OUTPUT:
teachers
OUTPUT:
01
4.5 Line number option(-n) :- This option will print out the line number with the record
thatcontain the specified pattern.
19 |P a g e
$ grep –n “for” largest.C for
OUTPUT:
4.6 Multiple pattern search option(-e) :- This pattern option allow us to search multiplepatterns
within a single command.
OUTPUT:
dp gupta
rk bakshi
2. EGERP:-
Extended GREP because it include two additional quantifier “?” and “+”. This is most powerful
command of grep family. It also include search for grep family. It also includes
search for multiple patterns. For this we use pipe character “|”.
OUTPUT:
rk bakshi
dp gupta
2.2 uses of additional quantifiers “+” and “?”:- + quantifier matches one or moreoccurrences
of previous character. For example ‘at’ matches a, aa, aaa and so on.
3. FGREP:-
Fixed Grep. It is used for fixed character patterns searching and does not make use of any
quantifiers. It is the fastest among entire pattern searching techniques.
$ fgrep “rk
20 |P a g e
> dp
> rajender
“teachers Or
rk
dp
rajender ctrl+d
$
Now we can search these words or patterns with –f o ption
$ egrep –f mp teachers
21 |P a g e
Practical No.-4
Problem Statement:
Compile and debug various C language based programs using ‘makefile’ & ‘debug’ utility.
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Commands:
Make a C Program:
1. Right click on Desktop→ Create Document→ Empty File. Open the file and write C
program and save it with .C extension.
2. Write a program using Cat command as,
$cat>largest.C
3. Write a program using vi Editor as,
$ vi largest.C
Run a C Program:
Program 1: hello.C
#include <stdio.h>
void main() {
printf(“Welcome”);
}
22 |P a g e
$gcc hello.C:- This command compile the hello.C program. If we want to run this program than
we have to run [Link] as,
$./[Link]
Output: Welcome
*/Note: Every C Program has the same output file as [Link] with rwx rwx r-x means 775 file
permission. Means user and group can read, write and execute every C program. But other
can read and execute program not write. /*
If we want to give every C Program different output file name then use this option for Compile
o is for ‘output’.
Program 2: largest.C
#include<stdio.h> void
main()
{
int a,b; printf(“Enter the values of a
and b”);
scanf(“%d %d”,&a,&b); if(a>b)
{
printf(“a is greater”); else
printf(“b is greater”); }
$./lar
20 13
a is greater
23 |P a g e
Makefile Utility: -
Makefile is a program building tool which runs on Unix/Linux. It aids in simplifying building
program executables that may need various modules. To determine how the modules, need to
be compiled or recompiled together, make takes the help of user-defined makefile. This tutorial
should enhance your knowledge about the structure and utility of [Link] guides the
make utility while compiling and linking program modules.
24 |P a g e
Process of Makefile:
1. Suppose, we have 3 files main.c (main source file), function1.c, function2.c and function3.c
(source files that contains function definition), functions.h (that contain function
declaration).
2. Here we will execute a program named Square root of number.
3. Makefile to compile these files. all:
gcc – o square main.c function1.c function2.c function3.c
4. Compile program/project using makefile
$ make
Debug utility:-
1. Compile your C program with -g option. This allows the compiler to collect the
debugging information.
a. gcc –g factorial.c
2. Launch the C debugger (gdb) as shown below.
a. gdb [Link]
3. Set up a break point inside C program
a. Syntax: break line_number
4. gdb command shortcuts
25 |P a g e
Practical No.-5
Problem Statement:
Learning of installation of dual operating system with Linux having previously installed
other window based operating system. Both OSs should be in working operating mode.
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Theory:
1. Overview: The Ubuntu desktop is easy to use, easy to install and includes everything youneed
to run your organisation, school, home or enterprise. It's also open source, secure, accessible and
free to download. 2. Requirements
• Ensure you have at least 25GB of free storage space, or 5GB for a minimal
installation.
•Have access to either a DVD or a USB flash drive containing the version of Ubuntu
you want to install.
· Make sure you have a recent backup of your data. While it's unlikely that anything will
go wrong, you can never be too prepared.
1. Make sure you have Windows 7 installed and running on your PC.
2. [OPTIONAL] You can prepare your disk by making available a free partition for
yourUbuntu. You may use the Disk management tool on Windows to do this or employ a
26 |P a g e
third party app such as Paragon Partition Manager or EaseUS Partition Manager. You
need at least 10GB of free space.
4. Make a bootable USB or disc of the Ubuntu iso you have downloaded. You can use Rufus
tool on windows or you c an use the Startup Disk Creator if you have an existing Ubuntu or
Linux installation.
27 |P a g e
5. Reboot your PC with
the bootable
USB or disc.
6. Proceed with the install
ation until you get to
Installation type. If you
created a partition
already (Step 2), then
choo se it at your target
install and continue the
p rocess. If you skipped
Step 2, choose one of
a. Choose the option
which says the
followings -
alongside
“Install Ubuntu partition size by dragging the slider at them” and then specify your the
bottom.
b. Choose “Something else”. Select the partition yo u want to resize and enter the Size in GB and
then press Enter to shrink your existing partition. You need at least 10GB of space for Ubuntu
and then another 4-8GB for SWAP. Use your installed RAM as a guide for SWAP.
Create a partition for your Ubuntu and then set the rest of free space as SWAP. Select "Finish
partitioning and write changes to disk".
28 |P a g e
7. Continue and then finish your Ubuntu Installation.
8. Your grub installation will automatically look for other installed operating systems and hence
will discover your existing Windows 7. Upon boot up, you will be presented with the option to
select your OS of choice.
29 |P a g e
30 |P a g e
Practical No.-6
Problem Statement:
As supervisor create and maintain user accounts, learn package installation, taking backups,
creation of scripts for file and user management, creation of startup and shutdown scripts
using at, batch, cron etc
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Theory:
1. Create and maintain user account :- We cannot create users on non-root terminal. If
we try to create user at non-root then we can get the message_ permission denied. So try to be
in root login or move from non-root to root with command Su(Super user or root) # :- Root or
super use
$ :-non root user or simple user
[rajender@localhost Desktop] $ useradd piet : permission denied
[rajender@localhost Desktop] $ Su Password:
[root@localhost Desktop]#
# hash mean we are at root user and we can create user here.
[root@localhost Desktop]# useradd PIET [root@localhost
Desktop]# passwd PIET
Changing password for user PIET New
password:
Retype new password:
Passwd: all authentication tokens updated successfully.
[root@localhost Desktop]#
Useradd :- command to create user account
[Link] :- command to set passwprd for user account.
31 |P a g e
[root@localhost Desktop]# userdel_PIET This command will delete the user account. 2.
Switching between users :- If we want to switch between useraccounts then
use[]$ Su –useraccount.
$ Su - [to switch from non root user to root]
[root@localhost ~]#
~ This sign indicate that we are using Root shell and # means root.
3. Software package installation :- We can install different package at the time of
installation of OS and later on as well. Different package of Linux OS are:-
Desktop Environment --> GNOME,KDE
Applications--> Editors , games, graphics, sound and video
Development--> Development tool, Software development
Server--> FTP, web server, mail server, DWS Base
system--> Java, base, system tool
Language--> Hindi, English, Punjabi
4. Creation of script for file :-
$ script This command is used to record the interactive session.
$ script
Script started, file is typescript
___
___
___
Exit
$ script done, file is typescript
The name of the file is typescript and always when we want to record the session it will be save
in typescript file so always give a new name to this typescript file after we recorded the last session.
We can see the record session by
$ more typescript
Creation of startup and shutdown scripts using at, batch, cron etc.
1. at command
This command is capable of executing Linux command at a future date and time. The input
to this command comes from the standard input like keyboard. Then the command typed.
Once the job is submitted using at command, all the details regarding job id no., date and time
at which commands are executed to be displayed.
For example:
$ at 10:45 Jun 23 2021 at>
cat>[Link]
ctrl+d
job 18 submitted at 2021-06-23 10:45
$
So [Link] file created at 10:45 on Jun 23, 2021. This is future time to execute a
command.
2. batch command
Job submitted by using batch command are executed when the system is relatively free and
system load is light. Time at which command will be executed is decided by the system.
$ batch
32 |P a g e
at> grep unix [Link]
ctrl+d
job 16.b at 2021-06-23 11:15
$
The extension. b attached to a job identification number indicated that the job has been
submitted using batch command.
Cron is a daemon that keep sleeping most of the time. It executes commands that need to be run regularly
according to the time schedule. The schedule and corresponding time is stored in the file /etc/[Link]
daemon wakes up every minute and check its crontab file for any job that need to be executed during this
minute.
Every entry in crontab file /etc/crontab contain six fields separated by space or tab in the following form.
1 2 3 4 5 6
Minute Hour Day of Month Month day of week command to be executed
$ crontab –l
no crontab for rajender
$
This file is submitted to crontab as:
$ crontab contentfile
33 |P a g e
Practical No.-7
Problem Statement:
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Theory:
ZIP is a compression and file packaging utility for Unix. ... zip is used to compress the files
toreduce file size and also used as file package utility. zip is available in many operating systems
like unix, Linux, windows etc.
ZIP is a compression and file packaging utility for Unix. Each file is stored in single .zip
{.zipfilename} file with the extension .zip.
• zip is used to compress the files to reduce file size and also used as file package
utility.
zip is available in many operating systems like unix, linux, windows etc.
• If you have a limited bandwidth between two servers and want to transfer the files
faster, then zip the files and transfer.
• The zip program puts one or more compressed files into a single zip archive, along
with information about the files (name, path, date, time of last modification, protection, and
check information to verify file integrity). An entire directory structure can be packed
into a zip archive with a single command.
• Compression ratios of 2:1 to 3:1 are common for text files. zip has one compression
method (deflation) and can also store files without compression. zip automatically chooses the
better of the two for each file to be compressed. The program is useful for packaging a set of
files for distribution; for archiving files; and for saving disk space by temporarily compressing
unused files or directories.
Syntax:
zip [options] zipfile files_list
34 |P a g e
Syntax for Creating a zip file:
Unzip will list, test, or extract files from a ZIP archive, commonly found on Unix systems.
The default behaviour (with no options) is to extract into the current directory (and sub-
directories below it) all files from the specified ZIP archive.
File Compression:
Sometimes it is useful to store a group of files in one file so that they can be backed up, easily
transferred to another directory, or even transferred to a different computer. It is also sometimes
useful to compress files into one file so that they use less disk space and download faster.
It is important to understand the difference and relationship between an archive file and a
compressed file. An archive file is a collection of files and directories that are stored in onefile.
The archive file is not compressed — it uses the same amount of disk space as all the individual
files and directories combined. A compressed file is a collection of files and directories that are
stored in one file and stored in a way that uses less disk space than all the individual files and
directories combined. If you do not have enough disk space on your computer, you can compress
files that you do not use very often or files that you want to save but do not use anymore. You
can even create an archive file and then compress it to save disk space.
Compressed files use less disk space and download faster than large, uncompressed files. In Red
Hat Linux you can compress files with the compression tools gzip, bzip2, or zip.
The bzip2 compression tool is recommended because it provides the most compression and is
found on most UNIX-like operating systems. The gzip compression tool can also be found on
most UNIX-like operating systems. If you need to transfer files between Linux and other
operating system such as MS Windows, you should use zip because it is more commonly used
on these other operating systems.
35 |P a g e
Compression Tools
Un-compression Tool
.gz Gunzip
Gzip
.zip Unzip
Zip
36 |P a g e
Practical No.-8
Problem Statement:
Familiarize with file permissions in Linux to keep users file secure from unauthorized access.
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an alternative
approach)
Theory:
File Permissions:
In a multiuser environment like Linux it becomes important for user to keep their files secure.
When a user creates a file, he becomes the owner of that file. Each user belongs to a group. A
user can also access to other groups. Hence there are three types of users in Linux- first is owner,
second is group and third others.
Types of Permissions:
1. Read
2. Write
3. Execute
These permission may be granted to all 03 categories of users. If you have read permission you
can view its contents. Write permission allow you change the file contents. Execute permission
means that you can run the file just like a program. Example: Shell program or C program.
37 |P a g e
$ls –l: ls command with –l option displays the permissions for the file. Note that the
outputdisplayed in the first column. The first character tells you about the type of the file. The
remaining 09 characters represent the permissions. The file permissions are divided into 03 sets
of
It means the owner of the file has read and write (modify) permission but do not have permission
to run(execute) the file as a program.
Other can only read and execute file but cannot write (modify) or run (execute) the file as program.
In linus you can change the file permissions by using chmod command. You can allow or prevent
yourself (owner), group or others from reading, writing and executing the file. In chmod
command, first specify for whom you are changing the permission,
u for user
o for others
Second you have to specify whether you want to allow or prevent the permission.
$ls –l: This command will list all the files and directories.
Output:
38 |P a g e
File→ -rw-rw-r--.1 rajender rajender 28 Sep 7 22:32 name
The name file has initially rw-rw-r—permission. Itmeans this file has not execute permission of
owner and group and It cannot modify nad execute by others.
If we want to execute this file by user (owner) and group then we have to write a command as
rw-rw-r—
u for user
g for group
This command will allow user and group to execute the name2 file as program. After this command
the file permission of file name2 will look like rwxrwxr—
Or
39 |P a g e
We can also set file permission using octal codes. In this code 03 digits are used.
One for owner (user), one for group and one for others.
Read(r) 4 0 0
Write (w) 2 0 0
Execute (e) 1 0 0
Sum 7 0 0
Each column represents a user and each row represents a file permission. If user has read
permission the owner 04 is added in that column, to set written permission 2 is added, to set
execute permission 1 is added the sum of each column is the code of that user permission.
Read(r) 4 4 0
Write (w) 2 0 0
Execute (e) 1 1 0
Sum 7 5 0
The above chmod command set read, write and execute permission for owner and read and execute
permission for the group.
40 |P a g e
It means read, write and execute permission for owner and group and only read is set for others.
41 |P a g e
Practical No.-9
Problem Statement:
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an alternative
approach)
Theory:
Sed is a stream editor used for modifying the files in UNIX or LINUX.
Whenever you want to make changes to the file automatically, sed is helpful in that . Apart
from replacing text, you can do many things with sed.
cat [Link]
(1) Replacing or substituting stringIt is mostly used to replace the text in a file.$ sed
‘s/unix/linux/’ [Link] linux is great OS. unix is open
source. unix is free OS. learn operating system.
42 |P a g e
linuxlinux which one you choose.
By default sed command replaces the first occurrence of pattern of each line and it would not
replace the second, third ….. occurrence in the line.
43 |P a g e
{unix} is great OS. unix is open source. unix is free OS.
44 |P a g e
linux is great OS. unix is open source. unix is free OS.
45 |P a g e
$ sed ‘3 s/unix/linux/’ [Link]
$ sed ‘2 d’ [Link]
46 |P a g e
(15) Sed as grep command
47 |P a g e
(18) Change a line with “c” option
$ sed ‘/unix/c “change line” ’ [Link]
“change line”.
“change line”.
48 |P a g e
Practical No.-10
Problem Statement:
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Theory:
AWK (Aho, Weinberger and Kernigham) is a filter Program that was originally developed in
1977 as a pattern scanning language. It is a programming language with block control structures,
functions and variables.
Where
49 |P a g e
This command will show the complete records of [Link]
Name Salary
A $20000
B $25000
C $26000
D $15000
E $11000
Name Salary
A $20000
B $25000
C $26000
D $15000
E $11000
[Link]
Sr. No. Name Designation Department Salary
4 D AP MECH $15000
5 E AP CIVIL $11000
50 |P a g e
[Link]
Sr. No. Name Designation Department Salary
5 E AP CIVIL $11000
This command will print the complete line if there is a match of column 4=civil, otherwise we
will not get any records.
Output
Output:
Name Designation
A AP
B AP
C AP
D AP
E AP
Report generated
-------------------------------
51 |P a g e
2
Output:
S. No. :: Salary
1 :: $20000
2 :: $25000
3 :: $26000
4 :: $15000
5 :: $11000
$ awk “BEGIN {for(i=1; i<=5; i++) print “s quare of” i, “is”, i*i}”
Output:
sqaure of 1 is 1
52 |P a g e
sqaure of 2 is 4
sqaure of 3 is 9
sqaure of 4 is 16
sqaure of 5 is 25
53 |P a g e
Practical No.-11
Problem Statement:
Familiarize with PERL and its commands in Linux. Software
and Hardware Requirements:
2 GHz dual core processor
25 GB of hard-drive space (or USB stick, memory card or external drive but see LiveCD for an
alternative approach)
Theory:
PERL stand for Practical Extraction and Report Language. It was developed in 1986 by Larry
Wall as an interpreter on UNIX. Initially it had an emphasis on system management and text
handling but with subsequent revisions Perl also become capable of handling regular expressions,
signals and network sockets too. So its program bears a similar resemblance to that of C programs.
Filename: chomp-operator
Output:
$perl [Link]
54 |P a g e
String1
String2
String3
Chomp $string02;
Chomp $string03;
Output:
$perl [Link]
Use of if statement:
if
If (“A” gt “a”)
55 |P a g e
Print (“This is ture \n\n”);
Else
Print(“default \n\n”);
Output:
$perl if_else.pl
This is true again
Filename: [Link]
$n1=<STDIN>;
$n2=<STDIN>;
$n3=<STDIN>;
Print”$n1 is largest”;
56 |P a g e
}
Else
12
23 is largest
57 |P a g e
($str2),”\n”; My $final-str = $str1.$str2;
Print “final string is: \ t $final–str \n and lengt h of final string after concatenation is \t “, leng th
($final–str),” \n”;
58 |P a g e