Difference between revisions of "File permission demonstration script"
From assela Pathirana
Jump to navigationJump to search
m (Text replace - '<pre>' to ' <pre>') |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
| Line 23: | Line 24: | ||
</pre> | </pre> | ||
will produce the following output: | will produce the following output: | ||
<pre> | <pre> | ||
umask file dirs files dirs | umask file dirs files dirs | ||
022 759 648 | 022 759 648 -rw-r--r-- drwxr-xr-x | ||
027 754 643 | 027 754 643 -rw-r----- drwxr-x--- | ||
002 775 664 | 002 775 664 -rw-rw-r-- drwxrwxr-x | ||
006 771 660 | 006 771 660 -rw-rw---- drwxrwx--x | ||
007 770 659 | 007 770 659 -rw-rw---- drwxrwx--- | ||
077 714 603 | 077 714 603 -rw------- drwx------ | ||
</pre> | </pre> | ||
[[Category:Computing]] | |||
Latest revision as of 19:11, 2 October 2009
#!/bin/bash
fmt="%7s%7s%7s%15s%15s\n"
printf $fmt umask file dirs files dirs
while read line
do
set -- $line
umask $1
touch tempfile
mkdir tempdir
fval=`ls -l tempfile|awk '{print $1}'`
dval=`ls -dl tempdir|awk '{print $1}'`
printf $fmt $1 "$(( 777 - $1 ))" "$(( 666 - $1 ))" $fval $dval
rm -rf temp*
done << EOF
022
027
002
006
007
077
EOF
will produce the following output:
umask file dirs files dirs
022 759 648 -rw-r--r-- drwxr-xr-x
027 754 643 -rw-r----- drwxr-x---
002 775 664 -rw-rw-r-- drwxrwxr-x
006 771 660 -rw-rw---- drwxrwx--x
007 770 659 -rw-rw---- drwxrwx---
077 714 603 -rw------- drwx------