Read a Unix mode from 755, rwxr-xr-x, an ls -l line or a chmod command and write it every way, umask and special bits too
Type a mode or paste an ls -l line to see who can read, change and run the file, the mode in octal, letters and chmod’s own words, and what deserves a second look.
How to use it
Type a mode like 755, paste the start of an ls -l line, or a whole chmod command; the page finds the mode in it. Short modes are read as chmod reads them: 7 is 007. To take rights away (g-w), write the current mode after it: g-w 775. Tick boxes in the grid to change it. The change is written back the way you typed it: octal stays octal, an ls line stays an ls line. Pick File or Directory: read, write and execute mean different things on a directory. Tick chmod’s options (-R, -v, -c, -f, --preserve-root) to add them to the command, or pick from More modes for 22 common modes.
Examples
An ls -l line
-rwxr-x--- 1 ada staff 4096 Oct 4 10:20 deploy.sh
Octal 750 Clauses u=rwx,g=rx,o= Owner read, change and run it Group read and run it Others nothing
A mode with the setuid bit
4755
ls -l -rwsr-xr-x Clauses u=rwx,g=rx,o=rx,u+s
The s where the owner’s x would be is setuid. /usr/bin/passwd has this mode on most Linux systems.
chmod’s own words
chmod u=rw,go=r notes.txt
644 rw-r--r--
Take a right away from the current mode
u+x,go-w 666
744 rwxr--r--
chmod changes the file’s current mode, so - needs it: here 666, the mode a new file gets with umask 000.
How the three digits work
| Mode | ls -l | Used for |
|---|---|---|
644 | -rw-r--r-- | ordinary files: web pages, config, documents |
755 | -rwxr-xr-x | scripts and programs; most directories |
600 | -rw------- | private files: an SSH private key, a .env file |
700 | drwx------ | a private directory, like ~/.ssh |
664 | -rw-rw-r-- | files a team edits together |
400 | -r-------- | a key or certificate no one should change |
1777 | drwxrwxrwt | /tmp: anyone can add files, only owners delete them |
On a directory, the rights mean something else
chmod’s options
| Option | What it does | macOS and BSD |
|---|---|---|
-R | every file and directory inside, too | yes |
-v | prints a line for each file | yes |
-c | prints a line only for files it changed | no |
-f | says nothing when a file can’t be changed | yes |
--preserve-root | refuses to work on / with -R | no |
--reference=FILE | copies FILE’s mode instead of a typed one | no |
Sources: GNU coreutils: chmod
Setuid, setgid and the sticky bit
Questions
- What does chmod 777 do, and why is it a bad idea?
It gives everyone on the machine read, write and execute. Any user or process can change or replace the file, so a script or a web page can be swapped for something else. 755 for programs and directories, 644 for files is usually what’s meant. - What is the difference between chmod 755 and chmod +x?
755 sets the whole mode at once. +x only adds execute and leaves read and write as they were; without u, g or o in front, chmod adds it for every class the umask allows. This page assumes umask 022 for that and says so. - What umask gives 755 directories and 644 files?
umask 022. A umask takes rights away from 777 for new directories and from 666 for new files, so 022 gives 755 and 644, and 027 gives 750 and 640. - How do I chmod only folders, or only files?
With find: find folder -type d -exec chmod 755 {} + sets every directory, and find folder -type f -exec chmod 644 {} + every file. chmod -R alone gives both the same mode. - Is the mode I type uploaded?
No. Everything runs in your browser, so your modes and file names stay on your device. Nothing you paste is uploaded unless you share it.