Rishita Os 2 1
Rishita Os 2 1
Permission Commands
1. Permission Types
o Owner permissions − The owner's permissions determine what actions the
owner of the file can perform on the file.
o Group permissions − The group's permissions determine what actions a user,
who is a member of the group that a file belongs to, can perform on the file.
o Other (world) permissions − The permissions for others indicate what action
all other users can perform on the file.
2. Examining Permissions
ls -l abc.txt
The first three characters (2-4) represent the permissions for the file's owner.
The second group of three characters (5-7) consists of the permissions for the group
to which the file belongs.
The last group of three characters (8-10) represents the permissions for everyone
else.
Numerical
Symbolic
umask
umask 0222
File
1. Obtain a complete list of all files & directories in the whole system & save the output
in a file?
ls -a > output.file
2. Create a file new_file. Assign all permissions to the owner and remove all permissions
from others using Relative assignment and Absolute assignment
Relative assignment
cat > new_file.txt
chmod u+rwx new_file.txt
Absolute assignment
cat > new_file1.txt
chmod 700 new_file.txt
3. Assuming that a file’s current permissions are “rw-r-xr—“, to specify the chmod
expression required to change them to:
i) r w x r w x r w x
[chmod 777 [filename]] in absolute and [chmod a=rwx [filename]] in relative.
ii) r - - r - - - - -
[chmod 440 [filename]] in absolute and [chmod ug=r, o-rwx [filename]] in relative.
iii) - - r - -r - -
[chmod 044 [filename]] in absolute and [chmod u-rwx [filename], go=r [filename]] in
relative.
v) - - - - - - - - -
[chmod 000 [filename] in absolute and [chmod ugo-rwx [filename]] in relative
4.Write a shell script which receives two filenames as argument it should check whether
the file content are same or not. if they are same then 2nd file should be deleted.
PASSED=$1
[ -d "$PASSED" ] && echo "directory"
[ -f "$PASSED" ] && echo "file"
6.Find out whether the specified file grants read, write or execute permission
7.Find out whether the file exists or not, if not then create a file
echo "enter filename"
read file
if [ ! -f $file ]
then
echo "No file named $file exists"
touch $file
echo "$file has now been created"
ls -l $file
else
echo "$file exists"
fi
8. Find out whether a file contains any data or not if it contains then display the content
of file
echo "Enter filename: "
read file
if [ -s $file ]
then
echo "$file contains some data which is displayed below"
cat $file
else
echo "$file is does not contain any data"
fi
10. To copy the contents of one file to another file in a separate directory
11. Write a shell script to display the size of files from current working directory
1. ps: ps command is used to list the currently running processes and their PIDs along with
some other information depends on different options
2. top: top command is used to show the Linux processes. It provides a dynamic real-time
view of the running system. Usually, this command shows the summary information of the
system and the list of processes or threads which are currently managed by the Linux Kernel
3. Last :Each time a user logs into the system, a record for that session is written to
the /var/log/wtmp file. last reads the file wtmp file and prints information about the logins
and logouts of the users. Records are printed in reverse time order, starting from the most
recent ones.
6. nice, renice,fg, bg
7. Write a shell script which takes a name as parameter and returns the PID(s) of
processes with that name.
processId=$(ps -ef | grep 'ps' | grep -v 'grep' | awk '{ printf $2 }' )
echo $processId
1. df:Linux df command is used to display the disk space used in the file system.
-h, --human-readable: It is used to display sizes in powers of 1024 (e.g., 1023M).
2.du : du command, short for disk usage, is used to estimate file space usage.
3. head :The head command, as the name implies, print the top N number of data of the
given input
tail :The tail command, as the name implies, print the last N number of data of the given
input.
2. Write a shell script to count the number of words enclosed between $ and # symbols.
3. Write a script to search for the word ‘exam’ in a file and display total no. of matching
words.
grep -o -i exam file2.txt | wc -l
Array
3. Write a script to enter some numbers in the array and print the sum of all the
numbers.
echo "enter num"
read num
sum=0
while [ $num -gt 0 ]
do
mod=$((num % 10))
sum=$((sum + mod))
num=$((num / 10))
done
echo $sum
4. Write a script to load an array with some contents, display them, unset the entire
array and load the new contents.
h='date +%H'
if [ $h -lt 12 ]; then
echo "good morning"
elif [ $h -lt 17 ]; then
echo "good afternoon"
else
echo "good night"
fi
1.Write a script to perform real number calculation and store result to third variable,
let’s say a=5.66, b=4.5, c=a+b
2.The marks obtained by student in five different subject are input through A keyboard
the student gets a division as per following rules:-
a. Percentage above or equal to 60% - 1st division
b. Percentage between 50 % & 59% - 2nd division
c. Percentage between 40 % & 49% - 3rd division
d. Less then 40% fail
echo "Enter marks of two subjects"
read m1
read m2
per=`echo \($m1 + $m2 \) / 2 | bc`
echo
echo "Percentage is $per"
if [ $per -ge 60]
then
echo "First division"
elif [$per -ge 50 -a $per -lt 60]
then
echo "Second division"
elif [$per -ge 40 -a $per -lt 50]
then
echo "Thid division"
else
echo "Fail"
fi
3.In a company an employee is paid as under –if its salary is <20,000 then HRA =10%
of basic salary and DA=90% of basic salary. If salary equal to or above 20,000 then
HRA =500 and DA = 98% of basic salary. If employee salary is input through keyboard,
write a shell script to find the gross salary.
fi
if [ $cp -gt $sp ]
then
s=$((cp - sp))
echo "loss $s"
else
s=$((sp - cp))
echo "profit $s"
fi