Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Q. 1. 1.

Display the calendar of NOV 2021


Ans. $cal 11 2021

2. Displays calendar of current, previous and next month.


Ans. $cal -3

3. State currently login users by command


Ans. $who

4. What are various options of kill commands?


Ans. kill -9 0: - kills all processes inclduing login shell
kill -9 $$: - kills login shell
kill processnumbers - kills the processes as per the specified process ids.

5. List the system calls for process management


Ans. fork(), exec(), exit(), wait().

Q. 2. 1. Write a command to copy a file to another given destination file


Ans. cp sourcefile destinationfile

2. Write a command breaks down a given file containing 100 lines into 25 lines in each
File. Mention the default files created by the above command where the broken files are
getting saved automatically
Ans. split -25 filename, xaa, xab, xac, xad are the files that are created

3. Display all the file name starting with a and ending with y
Ans. ls a*y

4. Display files with name containing exactly 5 letters


Ans. ls ?????

5. Display a command to combine two sets of file in Linux


Ans. cat file1 file2

Q. 3. 1. Write a shell script to display Fibonacci series for n numbers


Ans. #!/bin/bash
n = 10
a=0
b=1
for((i=0;i<n;i++)); do
echo '$a'
temp = $((a+b))
a = $b
b = $temp
done
echo

2. State the difference between Iteration and Recursion


Ans.
Iteration Recursion
Repetition of a process using for loops. A function calls itself to solve a problem.
It is controlled by loops. It is controlled by function calls.
It uses less memory. It uses more memory.
Eg: - for loops, while loops. Eg: - Fibonacci, factorial

3. Execute shell script by considering example like printing a table of a number by for
Loop
Ans. #!/bin/bash
number=5
echo "Multiplication table of $number:"
for (( i = 1; i <= 10; i++ )); do
result=$((number * i))
echo "$number x $i = $result"
done

Q. 4. 1. Write a shell script to copy source file into destination file


Ans. #!bin/bash
read -p "Enter the source file:" s_file
read -p "Enter the destination file"" d_file
$cp "$s_file" "$d_file"
echo "Successfully copied"

2. Write a shell script which displays all files in your directory


Ans. #!bin/bash
echo "The files in home directory: "
home="$HOME"
ls -p "$home" | grep -v ‘/’

3. What are the file test options with its meaning?


Ans. File options are:
i. -a file: - true if file exists
ii. -b file: - true if it is block special
iii. -c file: - true if it is character special
iv. -d file: - true if file exists and is a directory
v. -e file: - true if file exists
vi. -f file: - true if file exists and is a regular file
vii. -s file: - true if file exists and has a size greater than zero

Q. 5. 1. Write a shell script to display the list of all executable files in the current working
Directory
Ans. #!/bin/bash
echo "Executable files in the current directory:"
for file in *
do
if [ -x "$file" ] && [ -f "$file" ]; then
echo "$file"
fi
done

2. Write a shell script which accepts a file name and assign it’s all permissions
Ans. read -p "Enter the filename: " flnm
chmod 777 "$flnm"
3. Write all the test commands to check the permissions of the files
Ans. i. -r file: - true if readeable
ii. -w file: - true if writable
iii. -x file: - true if executable

Q. 6. 1. Write the commands to assign the following permission to above “Class” folder using
octal method. _rw_r_x_w_
Ans. chmod 652 Class

2. Write the commands to assign the following permission to above “Class” folder using
symbolic method. _r___w___x
Ans. chmod u=r, g=w, o=x Class

3. Write the permission assigned to files after execution of following commands.


$chmod 423 abc.txt
Ans. For owner, read permission is assigned, for group, write permission is assigned and
for others, execute and write permissions are assigned.

4. Assign read and write for the owner, only read permission for the group and others using
octal method for prr.txt file
Ans. chmod 644 pqr.txt

Q7. 1. Display with an example to find certain pattern within a file


Ans. grep “pattern” filename
Eg: - newfile contains Hello, this is David Goggins
Grep “David” newfile

2. Suggest the command to convert “NATIONAL ANTHEM” into lower case


Ans. echo "NATIONAL ANTHEM" | tr '[:upper:]' '[:lower:]'

3. Create a file and add few given lines into it. Replace the color green with blue
Peacock is our national bird.
It is green in color.
It dances during rainfall.
Ans. cat >newfile
Peacock is our national bird.
It is green in color.
It dances during rainfall.
sed -i 's/green/blue/g' newfile

4. Copy the second line of the above file and paste in 4th line and delete the 2nd line
Ans. sed -n ‘2p’ newfile >> temp
sed ‘2d’ newfile > temp2
cat temp2 > newfile
cat temp >> newfile
rm temp temp2

1. sed -n '2p' newfile >> temp: Copies the second line of "newfile" and appends it to a
temporary file called "temp."
2. sed '2d' newfile > temp2: Deletes the second line from "newfile" and saves the result
in a temporary file called "temp2"
3. cat temp2 > newfile: Copies the contents of "temp2" back to "newfile" without the
second line.
4. cat temp >> newfile: Appends the contents of "temp" to "newfile" as the fourth line.
5. rm temp temp2: Deletes the temporary files "temp" and "temp2."

5. Create a space at the top of the file and write the heading “National Bird”
Ans. sed -i '1s/^/National Bird\n/' newfile

Q. 8. 1. Create a directory named “Department”. Create another two directories inside the above.
Name them as Computer & Chemical. Create two files in each above directories with
subjects
OSY, CSS & Organic, Inorganic respectively.
Ans. mkdir Department
cd Departnment
mkdir Chemical
mkdir Computer
cd Chemcial
touch Organic
touch Inorganic
cd ..
cd Computer
touch OSY
touch CSS

2. Assign Read, write and execute permissions to subjects of chemical department in octal
method.
Ans. chmod 777 Organic
chmod 777 Inorganic

3. Assign user with execute permission, group with read and write permission and others
with all three permissions to OSY file in symbolic method.
Ans. chmod u+x,g+rw,o+rwx OSY

4. Explain the given permission CHMOD 444 css.txt


Ans. chmod 444 css.txt
It means user, group and others are given the permission to read.

You might also like