Osy PR QB
Osy PR QB
Give
stpes.
=> we use script command to record the activities performed by the user
Steps are :
script [filename]
statements
.
.
.
.
Press CTRl+d to stop recording
Bydefault the session is recorded into filename typescript
3. Give single statement command to display the calendar of previous current &
next month.
=> cal -3
17.Create files ‘exam1’ & ‘exam2’ with 5 lines text in each file. Merge ‘exam1’ &
‘exam2’ to a single file ‘exam’.
=> cat > exam1.txt
This is osy subject
This is osy practical exam
We are creating file
We are using cat command
File created
CTRL+d to exit
18.Create a new file ‘subject’ with 5 lines of text using cat command. Append 5
more line it.
=> cat >subject.txt
To append : cat exam2.txt >>subject.txt
This will append the content of exam2.txt in subject.txt
19.What are different options of ls command? Write down the command along
with the option and write the output.
=> ls command displays list of files and directories in alphabetical order that are
available in current directory or specific directory
Options are :
1) ls -l : it displays long list of files. It displays the characteristic of each file that are
file type, file name , file permission , username , user group name , size of file
,time and date of last modification
2) ls -a : displays all files including hidden file
3) ls -d : displays a list of directories
4) ls -r : display file name in reverse
5) ls -R : display recursive list of directory and subdirectories
6) ls -i : display inode that is index node or number for each file
28.What is default set of permissions given by the system to new file and directory?
=> for user read and write permission for group read permission for other read
permission
29.Create ‘OSY’ directory & Assign all the permissions to OSY directory for other
users using symbolic method.
=> mkdir OSY
chmod o+rwx OSY
30.Create ‘TYAN’ directory & Assign read & write the permissions to OSY
directory for group & other users using octal method.
=> mkdir TYAN
chmod 666 TYAN
31.Write the command for performing the following tasks sequentially
a. Display your current directory.
=> pwd
b. Create a directory ‘subject’ in the current directory.
=> mkdir subject
c. Create a file ‘sample’ in the directory ‘subject’
=> cd subject
cat >sample.txt
d. Remove the write permission for the owner for ‘sample’ using symbolic method
=> chmod u-w sample.txt
e. Delete the file ‘sample. What is an error message displayed?
=> remove wright protected regular file ‘sample.txt’?
32.What are the permissions assigned to the file after execution of following
commands?
a. chmod 700 abc
=> for user all permissions for group no permission for other no permission
b. chmod u+rwx, go-rwx file1 file 2
=> for user all permission for groud and other no permission
c. chmod 536 xyz
=> for user read and execute permission for group write and for other read and write
permission
33.Create new files ‘cup’ and ‘fan’ and perform the commands
chmod ugo=r cup
=> assigned absolute value only read to every user
chmod ugo+r fan
=> assigned read permission to all user and write permission is there for user
34.Assign read and write permission for the owner, write permission for the group
and execute permission for the others using octal method for the mfile.
=> chmod 621 file
35.Write commands to assign following permissions to the file OSY using octal
method
a. _ _ _ _ _ _ _ _ _
=> chmod 000 OSY
b. _rw_r_xr__
=> chmod 654 OSY
c. _r_xr_xr_x
=> chmod 555 OSY
36.Write commands to assign following permissions to the file OSY using symbolie
method.
a._rwxr_xr__
=> chmod u+rwx, g+rx, o+r OSY
37.Try the commands and write output with its meaning
i. tr “[a-f]” “[0-5]” < employee
=> it will translate a-f letters to 0-5 numbers in file employee
ii. tr –s “ ” < employee
=> it will remove all the extra spaces from the file
iii.tr –d “f” <employee
=> it will delete f letter from employee file
38.Do the following operations using vi editor
i. Cerate sample.txt file using vi editor
=> open vi
insert mode write 5 lines
escape and then :x sample.txt
ii. Insert 5 lines of text
=> vi sample.txt
insert mode and then add 5 lines
iii. Copy first 3 lines of text and paste at the end of file.
=> vi sample.txt
move cursor to the first line and then type 3yy
then move cursor to end of file and then paste using P
iv. Delete 4 to 6 lines of text in a file
=> 3dd or 4,6d
v. Display line numbers in a file.
=> :set number
39.Write a shell script to print table of given number using FOR loop.
=> read -p “Enter a number for multiplication : ” no
echo “Multiplication table of $no is :”
for i in 1 2 3 4 5 6 7 8 9 10
do
prod=`expr $no \* $i`
echo “$prod”
done
40.Execute shell script to print following pattern using FOR loop.
*****
****
***
**
*
=> for i in 5 4 3 2 1
do
for j in 1 2 3 4 5
do
if [ $j -le $i ]
then
echo -n “*”
fi
done
echo “ ”
done
41.Write a shell script to display Fibonacci series for n numbers. Input n from user.
=>
read -p “enter no of terms :” no
n1=0
n2=1
i=0
while [ $i -lt $no ]
do
echo “$n1”
n3=`expr $n1 + $n2`
n1=$n2
n2=$n3
i=`expr $i + 1`
done
45.Write a shell script to accept four digit number and perform addition of all
digits.
=>
read -p “Enter 4 digit no: ” no
sum=0
while [ $no -gt 0 ]
do
digit=`expr $no % 10`
sum=`expr $sum + $no`
no=`expr $no / 10`
done
echo “Sum is $sum”
46.Execute the script for the following
i. The for loop using day of week list.
=>
for day in Sunday Monday Tuesday Wednesday Thursday Friday Saturday
do
echo “day”
done
49.Write a shell script to copy source file into the destination file
=>
read -p "Enter source file :" src_file
read -p "Enter detination file :" dest_file
if [ ! -f $src_file ]
then
echo "$src_file doesn't exist "
exit
fi
if [ -f $dest_file ]
then
echo "$dest_file already exist cant copy"
exit 0
fi
else
cp $src_file $dest_file
echo "file copied successfully"
fi
50.Write a shell script to find smallest/greatest no among two/three no.s.
=>
read -p "Enter three numbers :" no1 no2 no3
if [ $no1 -gt $no2 -a $no1 -gt $no3 ]
then
echo "$no1 is greater"
elif [ $no2 -gt $no1 -a $no2 -gt $no3 ]
then
echo "$no2 is greater"
else
echo "$no3 is greater"
fi
51.Write a shell script which displays list of all directories in your home directories
=>
for fname in `ls -1`
do
if [ -d $fname ]
then
echo "directories are $fname "
fi
done
52.Write a shell script which displays list of all files in your home directory.
=>
for fname in `ls -1`
do
if [ -f $fname ]
then
echo "files are $fname "
fi
done
53.Write a file handling program . First check whether it is file or directory, then if
it is file the program shall ask user for choices of copying, removing and renaming
files. Use case statement.
=>
for fname in `ls -1`
do
if [ -f $fname ]
then
echo "1. copy"
echo "2. remove"
echo "3. rename"
read -p "Enter a choice " ch
case $ch in
1)
read -p "Enter source file :" src_file
read -p "Enter detination file :" dest_file
if [ ! -f $src_file ]
then
echo "$src_file doesn't exist "
exit
elif [ -f $dest_file ]
then
echo "$dest_file already exist cant copy"
exit 0
else
cp $src_file $dest_file
echo "file copied successfully"
fi ;;
2)
rm $fname ;;
3)
read -p "Enter new file name :" new
mv $fname $new;;
*)
echo "Invalid choice !!"
esac
elif [ -d $fname ]
echo "this is directory "
fi
54.Write a shell script which displays the list of all executable files in the current
working directory
=>
echo "executable file in current directory "
for fname in `ls -1`
do
if [ -f $fname -a -x $fname ]
echo "Executable files are $fname"
fi
done
55.Write a shell script which displays a list of all the files in the current directory to
which user has read, write and execute permission.
=>
echo “Files having read, write and execute permissions are :”
for fname in `ls -1`
if [ -r $fname -a -w $fname -a -x $fname ]
then
echo “$fname”
fi
done
56.Write a shell script which accepts a filename and assigns it all the permissions.
=>
read -p “Enter a file to which you want to apply all permission” fname
if [ -e $fname ]
chmod ugo+rwx $fname
echo “all permissions assigned ”
else
echo “file doesn’t exist”
fi