read write permissions code example
Example 1: Using shell script, display the contents of the present working directory. If it is an ordinary file print its permission and change the permissions to r--r--r--
for item in *
do
if [ -f $item ]
then
echo "----------------$item----------------"
if [ -x $item ]
then
echo "File in Executable mode"
chmod -x $item
echo "Executable permission Removed!"
fi
if [ -w $item ]
then
echo "File in Write mode"
chmod -w $item
echo "Write permission Removed!"
fi
if [ -r $item ]
then
echo "Already in read mode(r--r--r--)"
else
chmod +r $item
echo "Now the read permission granted "
fi
echo "final permission"
ls -al $item
fi
echo
done
Example 2: linux chmod permissions
The three rightmost digits define permissions for the:
file user, the group, and others.
7 read, write and execute rwx 111
6 read and write rw- 110
5 read and execute r-x 101
4 read only r-- 100
3 write and execute -wx 011
2 write only -w- 010
1 execute only --x 001
0 none --- 000