Write a shell script that displays list of all the files in the current directory to which user has read write and execute permissions.
Answers
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions. Write a Shell script that receives any number of file names as arguments checks if every argument supplied is a file or a directory and reports accordingly.
Answer:
#Write a shell script which displays a list of all the files in the current directory to which you have read, write and execute permissions.
Let's see the answer:-
Explanation:
clear
count=0
echo "Name of all files in current directory having all three permissions:"
for i in `ls`
do
if [ -r $i –a –w $i –a –x $i ]
then
echo File : $i
count=` expr $count + 1 `
fi
done
echo ― "Total number of such files are $count "
OUTPUT
$touch t1 t2 t3 t4
$ls -l t1 t2 t3 t4
test 1-rwxr----- 1 nhce cse 345 Jul 18 2019
test2 -rwxr----- 1 ubuntu ubuntu 134 Jan 28 2023
test3 -rw-r----- 1 ubuntu ubuntu 466 Jan 28 2023
test4 -rw-r----- 1 ubuntu ubuntu 345 Jan 28 2023
$sh 10a.sh Name of all files in current directory having all three permissions:
File : test1
File : test2
File : test3
File : test4
Total number of such files are 4