pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

chmod-calc Convert between numeric and symbolic chmod notation

⇔ Decode
Input0 chars
Output0 chars

Examples

Convert between numeric and symbolic chmod notation

Usage
"755
644
rwxr-xr--" | chmod-calc

Check if a deploy script has the right permissions

Usage
"700
600" | chmod-calc

Verify file permissions on uploaded files

Usage
"rwxrwxrwx
rw-r--r--" | chmod-calc
View source
(input)=>{
                return input.trim().split("\n").map((line)=>{
                    line = line.trim();
                    if (!line) return "";
                    if (/^\d{3,4}$/.test(line)) {
                        const digits = line.slice(-3);
                        const sym = [
                            ...digits
                        ].map((d)=>{
                            const n = parseInt(d);
                            return ((n & 4 ? "r" : "-") + (n & 2 ? "w" : "-") + (n & 1 ? "x" : "-"));
                        }).join("");
                        return `${line} \u2192 ${sym}`;
                    }
                    if (/^[rwx-]{9}$/.test(line)) {
                        const num = [
                            0,
                            3,
                            6
                        ].map((i)=>{
                            const c = line.slice(i, i + 3);
                            return ((c[0] === "r" ? 4 : 0) + (c[1] === "w" ? 2 : 0) + (c[2] === "x" ? 1 : 0));
                        }).join("");
                        return `${line} \u2192 ${num}`;
                    }
                    return `${line} \u2192 Error: expected 3-digit octal or 9-char rwx string`;
                }).join("\n");
            }

Related Tools