Smriti (2319017) Ulp File
Smriti (2319017) Ulp File
PRACTICAL FILE
of
CODE: PC-CS-306LA
SUBMITTED IN PARTIAL FULFILLMENT OF THE
REQUIREMENTS FOR THE AWARD OF
BACHELORS OF TECHNOLOGY (B.TECH.)
IN
COMPUTER SCIENCE AND ENGINEERING
(SESSION: 2019-2023)
SUBMITTED BY:
Harshita
2319023
1
2319017
INDEX
S.NO PRACTICAL AIM DATE SIGNATURE
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
2
2319017
Practical 1
3
2319017
ls: This command is used to show all the directories and files at current
path.
Attributes:
o ls -l: shows file or directory, size, modified date and time, file or
folder name and owner of file and its permission.
4
2319017
o ls -li: This command prints the index number if file is in the first
column.
5
2319017
6
2319017
mkdir and rmdir: “mkdir” is used to make a new directory and “rmdir” is
used to delete a directory.
man: it is used if we want to know about details of any command for e.g.
“man touch”.
7
2319017
cp: used to copy file or directory from one directory to another directory.
Its syntax is like this “cp *FILE_OR_DIRECTORY_NAME*
*DIRECTORY_WHERE_WANT_TO_COPY*”.
8
2319017
locate: used to locate file in the file system. It’s almost same as searching
in windows. It gives us output of the path where the file is located in.
Note – we need to install a separate package for this command to work.
echo and cat: ”echo” is used to enter the text information in a “.txt” file
or any other editable text file. If the file is not present in the system then
the new file will be made of the name that we have given.
“cat” is used to show view the contents of that or any other file as shown
in the screenshot.
df: used to displays the amount of disk space available on the file system
containing each file name argument. Disk space is shown in 1 K blocks by
default
Attributes:
9
2319017
o df -m: same as “df” but shows the space in Mega Bytes (MB).
du: The Linux “du” (Disk Usage) is a standard Unix/Linux command, used
to check the information of disk usage of files and directories on a
machine.
10
2319017
Attributes:
11
2319017
o %p: AM or PM
12
2319017
o %Y: year
tty: used to display the file name of the terminal connected to standard
input.
13
2319017
Attributes:
14
2319017
wc: used to see the word count (how many words are there) in a “.txt” or
any other file containing any text information.
clear: used to clear termina window text. e.g. any other previous
commands typed in the terminal.
Before executing “clear” command:
15
2319017
Practical 2
The VI editor is the most popular and classic text editor in the Linux family.
Below, are some reasons which make it a widely used editor –
It is available in almost all Linux Distributions
It works the same across different platforms and Distributions
It is user-friendly. Hence, millions of Linux users love it and use it for their
editing needs
Nowadays, there are advanced versions of the vi-editor available, and the most
popular one is VIM which is Vi Improved. Some of the other ones are Elvis, Nvi,
Nano, and Vile. It is wise to learn vi because it is feature-rich and offers endless
possibilities to edit a file.
To work on VI editor, you need to understand its operation modes. They can be
divided into two main parts.
Command Mode
Insert Mode
Command Mode:
The vi editor opens in this mode, and it only understands commands
In this mode, you can, move the cursor and cut, copy, paste the text
This mode also saves the changes you have made to the file
Commands are case sensitive. You should use the right letter case.
This mode is for inserting text in the file.
You can switch to the Insert mode from the command mode by pressing
'i' on the keyboard.
16
2319017
Once you are in Insert mode, any key would be taken as an input for the
file on which you are currently working.
To return to the command mode and save the changes you have made
you need to press the Esc key.
Launching vi Editor:
To launch the VI Editor -Open the Terminal (CLI) and type
vi <filename_NEW> or <filename_EXISTING>
And if you specify an existing file, then the editor would open it for you to edit.
Else, you can create a new file.
After executing this command, we enter in command mode with the file name
written at bottom:
17
2319017
18
2319017
Here are some commands that are used in command mode in vi editor:
A - Write at the end of line (goes into insert mode)
Initial state:
After pressing A:
dd – Delete line
Initial state:
19
2319017
We can see here that “Hope you are good.” entry was deleted from the file.
After Pressing o:
After pressing p:
After pressing u:
20
2319017
After pressing D:
dw - Delete word
Initially:
21
2319017
cw - Change word
Initially:
After pressing x:
r - Replace character
Initially:
22
2319017
After pressing r:
k - Move cursor up
j - Move cursor down
h - Move cursor left
l - Move cursor right
23
2319017
PRACTICAL – 3
Aim: Shell programing using vi editor to get and enter student details.
Shell Programing: - Usually shells are interactive that mean, they accept
command as input from users and execute them.
24
2319017
PRACTICAL 4
25
2319017
PRACTICAL 5
GREP Commands :- The grep filter searches a file for a particular pattern of
characters and displays all the lines that contain the pattern that is searched in
the file is referred to as regular expression. The ‘ GREP ‘ stands for Globally
Search For Regular Expression And Print Out.
26
2319017
Practical 6
Aim: Write a program in shell that searches a particular pattern of string from
a file. File name and pattern is taken from the user.
Source Code:
OUTPUT:
27
2319017
Practical 7
SED command in UNIX stands for stream editor and it can perform lots of
functions on file like searching, find and replace, insertion or deletion. Though
most common use of SED command in UNIX is for substitution or for find and
replace. By using SED you can edit files even without opening them, which is
much quicker way to find and replace something in file, than first opening that
file in VI Editor and then changing it.
- SED is a powerful text stream editor. Can do insertion, deletion, search and
replace(substitution).
Syntax:
$sed [option] ‘address action’ filename
Options:
- ‘-n’: by default sed displays or prints the line selected for the processing.
To supress the default printing we use -n option
Examples:
1.Here we will print the line 1 from the file name egrep-test.txt
28
2319017
29
2319017
Practical 8
Syntax:
$awk options ‘pattern {action}’ filename
Commands:
1. Print all the lines (we can do it by using {print} or {print $0} in action)
Using print only
Using $0
30
2319017
31
2319017
Print records whose name is vishakha and grade is A+ and print whose
name is smriti or marks are 80.
4. usage of NR
using NR command print number of records with row number
32
2319017
Usage of ORS
33
2319017
Practical 9
Output –
34
2319017
Output –
35
2319017
Output –
36
2319017
Practical 10
Source Code –
Output –
37
2319017
Practical 11
Aim: Program for showing arithmetic operations using Perl commands.
Source Code –
Output –
38
2319017
Practical 12
Aim: Program to find factorial of given number.
Source Code –
Output –
39
2319017
Practical 13
40
2319017
For a running program (named process) Pid of finds the process id’s
(pids)
Fields described by ps are described as -
1. UID: User ID that this process belongs to (the person running it)
2. PID: Process ID
3. PPID: Parent process ID (the ID of the process that started it)
4. C: CPU utilization of process
5. STIME: Process start time
6. TTY: Terminal type associated with the process
7. TIME: CPU time is taken by the process
8. CMD: The command that started this process
There are other options which can be used along with ps command-
-a: Shows information about all users
-x: Shows information about processes without terminals
-u: Shows additional information like -f option
-e: Displays extended information
Stopping a process -
When running in foreground, hitting Ctrl + c (interrupt character) will
exit the command. For processes running in background kill command
can be used if it’s pid is known.
41
2319017
Other commands -
bg - A job control command that resumes suspended jobs while keeping
them running in the background.
If we use $>bg command in the terminal then it brings the most recent
process to the background.
42
2319017
43
2319017
Practical 14
Aim: Familiarize with at and batch command.
‘at’ - This is a command-line utility that allows you to schedule commands to be
executed at a particular time. Jobs created with at are executed only once.
How to use at command -
Simplified syntax for at command
Syntax - >$ at [options] runtime
The at command takes the date and time (runtime) when you want to execute
the job as a command-line parameter, and the command to be executed from
the standard input.
The command will display the job number and the execution time and date.
‘batch’ - batch or its alias at -b schedules jobs and executes them in a batch
queue when the system load level permit. By default, the jobs are executed
when the system load average is below 1.5. The value of the load can be
specified when invoking the at daemon. If the system load average is higher the
specified one, the jobs will wait in the queue.
To create a job with batch, pass the commands you want to execute:
44