-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint-chflags
More file actions
executable file
·51 lines (43 loc) · 857 Bytes
/
print-chflags
File metadata and controls
executable file
·51 lines (43 loc) · 857 Bytes
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
#!/bin/bash
readonly FLAGS=(arch archived opaque nodump sappnd sappend schg schange simmutable uappnd uappend uchg uchange uimmutable hidden)
printFlagsIfPresent() {
possibleFlag=$(echo "$1" | awk '{ print $5 }')
if [ "$possibleFlag" != "-" ]; then
for flag in ${FLAGS[@]}; do
if [ "$possibleFlag" == "$flag" ]; then
echo -n "$flag: "
echo $1 | cut -d ' ' -f 10-
break
fi
done
fi
}
printHelp() {
echo "usage: $0 [-r] FILES DIRECTORIES"
exit 1
}
if [ "${1}" == "-h" ]; then
printHelp
fi
if [ "${1}" == "-r" ]; then
# remove -r parameter
shift
recursive=true
else
recursive=false
fi
if [ $# -eq 0 ]; then
printHelp
fi
if [ $recursive = true ]; then
ls -RlOA "$@" |
while read lsLine; do
printFlagsIfPresent "$lsLine"
done
else
ls -lOA "$@" |
while read lsLine; do
printFlagsIfPresent "$lsLine"
done
fi
exit 0