You are on page 1of 14

URVASHI SAPRA 08590202018

Linux Internal Practical


1. Execute and explain three usage of Cat commands.
CAT COMMAND:- The cat (short for concatenate) is one of the most frequently
used commands in Linux. It is used to list the contents of a file on the standard
output (sdout).
THREE USAGE OF CAT COMMAND ARE:-
i. cat command to create a file
SYNTAX :- $cat > [filename]

This command will create a file with the content entered by user.
ii. cat command to display the file and the content of the file
SYNTAX :- $cat [filename]

This command will display the content of a file.

1
URVASHI SAPRA 08590202018

iii. cat command to merge two files


SYNTAX :- $cat [filename1] [filename2]

This command will merge the content of two files.


2. Write a shell script showing usage of command line variables.
CODING:

2
URVASHI SAPRA 08590202018

OUTPUT:

Command line arguments will display the input with the help of special variable
3. Execute and explain following.
a)

This program shows the sum of 20 numbers that is 0,0+1=1, 1+2=3 and so on.

3
URVASHI SAPRA 08590202018

b) cut –d “|” –f3 emp.txt |sort | uniq –c

c) sed command with any five options


SYNTAX:- $sed OPTIONS... [SCRIPT] [INPUTFILE...]
SED command in UNIX is stands for stream editor and it can perform lot’s of
function on file like, searching, find and replace, insertion or deletion.
THE FIVE OPTIONS ARE AS FOLLOWS:-
i. REPLACING OR SUBSTITUTING STRING
SYNTAX:- $sed 's/[pattern1]/[pattern2]/' filename

Sed command is mostly used to replace the text in a file. The below simple sed
command replaces the word “linux” with “unix” in the file.

4
URVASHI SAPRA 08590202018

ii. REPLACING ALL THE OCCURRENCE OF THE PATTERN IN A


LINE
SYNTAX:- $sed 's/[pattern1]/[pattern2]/g' filename

The substitute flag /g (global replacement) specifies the sed command to replace
all the occurrences of the string in the line.
iii. PARENTHESIZE FIRST CHARACTER OF EACH WORD
SYNTAX:- $ echo "HELLO TO LINUX PRACTICAL" | sed 's/\(\b[A-Z]\)/\(\1\)/g'
This sed example prints the first character of every word in parenthesis

This command will put first letter of each word into parenthesis.
iv. SED COMMAND TO DELETE A LINE
SYNTAX:- $sed 'nth line deletion' [filename]

This command will delete the number of line entered by the user.
5
URVASHI SAPRA 08590202018

v. SED COMMAND TO QUIT AFTER REDAING CERTAIN NUMBER OF


LINE
SYNTAX:- $sed '[lineNO]q' [filename]

This command will exit after a certain number of line which is entered by the user
d)chmod a-x, go+r xstart; ls –l xstart

e)bc <calc.txt> result.txt

This command will tranfer the result to result.txt after performing the
mathematical operation in calc.txt

6
URVASHI SAPRA 08590202018

f) Write command to display todays date along with message “Today date
is”
SYNTAX :- echo "Today's date is: $(date +%D)".

g) Write a Command to count number of users.

We can have a list of user using who command with a pipeline of wc -l command
According to above output as working on a terminal the log in users will be
shown 0 because no new user is using the terminal.

7
URVASHI SAPRA 08590202018

h) Grep commands with any five options


SYNTAX :- $grep [options] pattern [files]
The grep filter searches a file for a particular pattern of characters, and displays all
lines that contain that pattern.

i. Grep command to print only a count of the lines that match a pattern.
SYNTAX :- $grep -c [pattern] [filename]

8
URVASHI SAPRA 08590202018

ii. Grep command to display the matched lines, but do not display the
filenames.
SYNTAX :- $grep -h [pattern] [filename]

9
URVASHI SAPRA 08590202018

iii. This option in Grep command ignores case for matching.


SYNTAX :- $grep -i [pattern] [filename]

10
URVASHI SAPRA 08590202018

iv. Grep command to display list of a filenames only.


SYNTAX :- $grep -l [pattern] [filename]

11
URVASHI SAPRA 08590202018

v. Grep command to display the matched lines and their line numbers.
SYNTAX :- $grep -n [pattern] [filename]

12
URVASHI SAPRA 08590202018

i)Explain tr command with example


SYNTAX:- $tr [OPTION] SET1 [SET2]
The tr command in UNIX is a command line utility for translating or deleting
characters. It supports a range of transformations including uppercase to lowercase,
squeezing repeating characters, deleting specific characters and basic find and
replace
Example:- TR COMMAND TO TRANSLATE LOWER CASE TO UPPER
CASE IN A FILE
SYNTAX:- $cat filename | tr "[a-z]" "[A-Z]"

13
URVASHI SAPRA 08590202018

4 Write a script to check whether string is palindrome or not


CODING:

OUTPUT:

14

You might also like