现在你应该已经知道数字型态个更改权限方式为『三个数字』的组合, 那么如果在这三个数字之前再加上一个数字的话,那最前的面数字就代表这几个属性了! ( 注:通常我们使用 chmod xyz filename 的方式来设定 filename 的属性时,则是假设没有 SUID, SGID 及 Sticky bit 啦! )
? 4 为 SUID
? 2 为 SGID
? 1 为 Sticky bit
假设要将一个档案属性改为『 -rwsr-xr-x 』时,由于 s 在使用者权限中,所以是 SUID ,因此, 在原先的 755 之前还要加上 4 ,也就是:『 chmod 4755 filename 』来设定!此外,还有大 S 与大 T 的产生喔!
呵呵,现在是自己写的脚本,希望大家指点:
1 #!/bin/bash
2 MYDIR='/data/share'
3
4 judgedirexist(){
5 if [ ! -d $1 ]; then
6 mkdir -p $1
7
8 else
9 if [ `ls $1 | wc -l` != '0' ];then
10
11 read -p 'this dir is exist,y\Y is continue esle exit!' CHOOSE
12 [ $CHOOSE == 'Y' -o $CHOOSE == 'y' ] && echo 'continue......' || exit 1
13 fi
14 fi
15 }
16
17 creatgroup(){
18 read -p 'please input a name:' MYGNAME
19 while grep "^$MYGNAME:x:" /etc/group &> /dev/null ; do
20 # [ $? == '0' ] && echo 'groupname exit,input again....' && exit 1
21 # while [ $? == '0' ]; do
22 read -p 'gname is exist please input a name again:' MYGNAME
23 done
24
25 read -p 'please input a Gid:' MYGID
26
27 while grep ":x:$MYGID:" /etc/group &> /dev/null; do
28
29 read -p 'Gid is exist please input again:' MYGID
30 done
31 groupadd -g $MYGID $MYGNAME &> /dev/null || echo ' GID exit ,input again.....'
32
33 }
34
35 creatuse(){
36 read -p 'please input a username:' MYUNAME
37 id $MYUNAME &> /dev/null && echo 'usre exist .....' || useradd $MYUNAME
38 [ $? == '0' ] && usermod -G $MYGID $MYUNAME
39 # useradd $MYUNAME
40 read -p 'please input passwd ,null is default:' MYPASSWD
41
42 [ -z $MYPASSWD ] && MYPASSWD='redhat'
43 echo "$MYPASSWD" | passwd --stdin $MYUNAME &> /dev/null
44 [ $? == '0' ] && echo 'create scessfull....' || echo 'create fail!!!'
45 }
46
47 changgroup(){
48 #$1 is groupown $2 is file
49 chgrp $1 $2
50 chmod 3775 $2 && echo "change secssful `ls -dl $2`"
51
52 }
53
54
55
56
57 judgedirexist $MYDIR
58 creatgroup
59 creatuse
60 creatuse
61 changgroup $MYGNAME $MYDIR