You are on page 1of 4

Name : Aditya B.

Thakare Practical no : 13
Roll no : 39

Program Code

1. Write a shell script to find out whether - File has read, write and
execute permissions.

echo "Enter the File: "


read line
if [ -r "$line" ]; then
echo "$line has read permission."
fi
if [ -x "$line" ]; then
echo "$line has execute permission."
fi
if [ -w "$line" ]; then
echo "$line has write permission."
fi

Output
Name : Aditya B. Thakare Practical no : 13
Roll no : 39

Exercise
1. Write a shell script which displays the list of all executable files in
the current working directory

pwd
ls > f
exec < f
while read line
do
if [ -f "$line" ]
then
if [ -x "$line" ]
then
echo "$line"
fi
fi
done

Output

2. 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.

pwd
ls > f
exec < f
while read line
do
Name : Aditya B. Thakare Practical no : 13
Roll no : 39
if [ -f "$line" ]; then
if [ -r "$line" -a -w "$line" -a -x "$line" ]; then
echo "$line has all the permissions."
fi
fi
done

Output
Name : Aditya B. Thakare Practical no : 13
Roll no : 39
3.Write a shell script which accepts a filename and assign it all the
permissions.

echo "ENTER THE FILE : "


read file
chmod u+xrw "$file"
chmod o+xrw "$file"
chmod g+xrw "$file"

Output

You might also like