Skip to content

Instantly share code, notes, and snippets.

@teramako
Last active September 7, 2022 13:03
Show Gist options
  • Save teramako/d4de43fba57700149baee9899a0c58c2 to your computer and use it in GitHub Desktop.
Save teramako/d4de43fba57700149baee9899a0c58c2 to your computer and use it in GitHub Desktop.
rwxなパーミッションを8進数表記に変換するsedスクリプト。 ls -l | sed -f perm2oct.sed
#!/usr/bin/sed -f
# SUID, GUID, Sticky-bit
s/^\(.\)\(..[sS]..[sS]..[tT]\)/\17\2/; t perm
s/^\(.\)\(..[sS]..[sS]..[^tT]\)/\16\2/; t perm
s/^\(.\)\(..[sS].\{5\}[tT]\)/\15\2/; t perm
s/^\(.\)\(..[sS][^sStT]\{6\}\)/\14\2/; t perm
s/^\(.\)\([^sS]\{5\}[sS]..[tT]\)/\13\2/; t perm
s/^\(.\)\([^sS]\{5\}[sS][^tT]\{3\}\)/\12\2/; t perm
s/^\(.\)\([^sS]\{8\}[tT]\)/\11\2/; t perm
s/^\(.\)\([^sStT]\{9\}\)/\10\2/;
:perm
s/rw[xst]/7/g;
s/rw[ST-]/6/g;
s/r-[xst]/5/g;
s/r-[ST-]/4/g;
s/-w[xst]/3/g;
s/-w[ST-]/2/g;
s/--[xst]/1/g;
s/--[ST-]/0/g;
#!/bin/bash
DIR=tmp
mkdir ${DIR}
for (( i = 0; i <= 0777; i++ )); do
P=$(printf "%04o" $i);
touch ${DIR}/perm_$P;
chmod $P ${DIR}/perm_$P;
done
ls -l tmp | ./perm2oct.sed
rm -rf ${DIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment