-
Notifications
You must be signed in to change notification settings - Fork 151
/
chmod.sh
100 lines (70 loc) · 1.7 KB
/
chmod.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
## chmod
# POSIX
# Change file permissions
# Syntax:
# chomod [ugoa][+-=][rwxXst]+
# Make f executable for all (owner, group and other);
chmod a+x "$f"
# Makes f readable for all:
chmod a+r "$f"
# The difference between using `a` and nothing is that when using
# nothing `umask` comes into play.
umask 002
chmod +w "$f"
stat -c "%a" "$f"
#220
chmod a=w "$f"
stat -c "%a" "$f"
#222
chmod o=w "$f"
stat -c "%a" "$f"
#002
# Make f not executable for all:
chmod -x "$f"
# Make file not executable and not writeble by all:
chmod =r "$f"
# Make f executable for owner:
chmod u+x "$f"
# Makes f executable for group and other:
chmod go+x "$f"
# Makes f readable and writible for all:
chmod +rw "$f"
# Same as `chmod =rwx`:
chmod 777 "$f"
## sticky bit, suid sgid bits
# Sticky bit:
chmod 1000 "$f"
chmod o=t "$f"
chmod a=t "$f"
stat -c "%A" "$f"
#---------T
chmod a-t "$f"
chmod u=t "$f"
chmod g=t "$f"
stat -c "%A" "$f"
#---------T
chmod =s "$f"
chmod 6000
#set suid and sgid
chmod u=s "$f"
chmod 4000
#set suid and sgid
chmod g=s "$f"
chmod 2000
# Can't clear them on numeric mode, only symbolic:
chmod 7777 f
stat -c "%A" "$f"
#-rwsrwsrws
chmod 0 f
stat -c "%A" "$f"
#---S--S--T
chmod a-st f
stat -c "%A" "$f"
#----------
# Can only change permissions for files you own
# even if you do not have all the permissions on the file:
su a
touch a
chmod 777 a
su b
if ! chmod 770 a; then assert true; fi