-
Notifications
You must be signed in to change notification settings - Fork 151
/
chown.sh
39 lines (27 loc) · 843 Bytes
/
chown.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
## chown
# POSIX 7
# Change owner and group of files.
# You must use sudo to do this, because otherwise users would be able to:
# - steal ownership of files
# - git ownership to users who do not want to own the files
su a
mkdir d
touch d/f
sudo chown newuser:newgroup d
#must use sudo to chown
[ `stat -c '%U' d` = newuser ] || exit 1
[ `stat -c '%G' d` = newgroup ] || exit 1
[ `stat -c '%U' d/f` = a ] || exit 1
# `-R` for recursive operation:
su a
mkdir d
touch d/f
sudo chown b d
[ `stat -c '%U' d` = newuser ] || exit 1
[ `stat -c '%G' d` = newgroup ] || exit 1
[ `stat -c '%U' d/f` = newuser ] || exit 1
[ `stat -c '%G' d/f` = newgroup ] || exit 1
# To change only user:
sudo chown newuser
# To change only group:
sudo chown :newgroup