Professional Documents
Culture Documents
OSY Practice Questions
OSY Practice Questions
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
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. 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
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
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