This tutorial will show you how to generate all the permissions using one file named
file_test.
[mythcat@desk ~]$ mkdir my_bash_scripts
[mythcat@desk ~]$ cd my_bash_scripts/
[mythcat@desk my_bash_scripts]$ vim all_permissions.sh
[mythcat@desk my_bash_scripts]$ vim all_permissions.sh
[mythcat@desk my_bash_scripts]$ chmod +x all_permissions.sh
[mythcat@desk my_bash_scripts]$ ls
all_permissions.sh
Let's see the bash script file named
all_permissions.sh:
#!/bin/sh
#loops through a chmod sequence
count_perm(){
foo=1
touch file_test
while [ "$foo" -ne 7778 ];do
echo $foo >> out
chmod $foo file_test
ls -gG >> out
foo=$(($foo+1))
done
}
count_perm
egrep -v '(all_permissions.sh)|(total)|(out)' out > results
echo "use command cat results to see permissions for file_test."
exit 0
You can run the script:
[mythcat@desk my_bash_scripts]$ ./all_permissions.sh
...
Try 'chmod --help' for more information.
chmod: invalid mode: ‘7768’
Try 'chmod --help' for more information.
chmod: invalid mode: ‘7769’
Try 'chmod --help' for more information.
use command cat results to see permissions for file_test.
[mythcat@desk my_bash_scripts]$ ls
all_permissions.sh file_test out results
The
out file show all permissions for files:
[mythcat@desk my_bash_scripts]$ cat out
...
7774
total 2052
-rwxrwxr-x. 1 331 Nov 10 18:22 all_permissions.sh
-rwsrwsr-T. 1 0 Nov 10 18:23 file_test
-rw-rw-r--. 1 1153701 Nov 10 18:23 r
7775
total 2052
-rwxrwxr-x. 1 331 Nov 10 18:22 all_permissions.sh
-rwsrwsr-t. 1 0 Nov 10 18:23 file_test
-rw-rw-r--. 1 1153853 Nov 10 18:23 r
7776
total 2052
-rwxrwxr-x. 1 331 Nov 10 18:22 all_permissions.sh
-rwsrwsrwT. 1 0 Nov 10 18:23 file_test
-rw-rw-r--. 1 1154005 Nov 10 18:23 r
7777
total 2052
-rwxrwxr-x. 1 331 Nov 10 18:22 all_permissions.sh
-rwsrwsrwt. 1 0 Nov 10 18:23 file_test
-rw-rw-r--. 1 1154157 Nov 10 18:23 r
The
results file show the permissions:
[mythcat@desk my_bash_scripts]$ cat results
...
7766
-rwsrwSrwT. 1 0 Nov 10 18:30 file_test
7767
-rwsrwSrwt. 1 0 Nov 10 18:30 file_test
7768
-rwsrwSrwt. 1 0 Nov 10 18:30 file_test
7769
-rwsrwSrwt. 1 0 Nov 10 18:30 file_test
7770
-rwsrws--T. 1 0 Nov 10 18:30 file_test
7771
-rwsrws--t. 1 0 Nov 10 18:30 file_test
7772
-rwsrws-wT. 1 0 Nov 10 18:30 file_test
7773
-rwsrws-wt. 1 0 Nov 10 18:30 file_test
7774
-rwsrwsr-T. 1 0 Nov 10 18:30 file_test
7775
-rwsrwsr-t. 1 0 Nov 10 18:30 file_test
7776
-rwsrwsrwT. 1 0 Nov 10 18:30 file_test
7777
-rwsrwsrwt. 1 0 Nov 10 18:30 file_test