CtrlK
BlogDocsLog inGet started
Tessl Logo

chmod

Change file mode/permissions. Use when setting read/write/execute permissions on files and directories.

64

Quality

76%

Does it follow best practices?

Impact

No eval scenarios have been run

SecuritybySnyk

Advisory

Suggest reviewing before use

Optimize this skill with Tessl

npx tessl skill review --optimize ./.flox/pkgs/skill-coreutils/skills/chmod/SKILL.md
SKILL.md
Quality
Evals
Security

chmod - Change File Mode Bits

Synopsis

chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...

Change the file mode bits of each FILE to MODE. MODE can be symbolic or octal.

Flags

FlagLong FormDescription
-R--recursiveChange files and directories recursively
-v--verboseOutput a diagnostic for every file processed
-c--changesLike -v but only report changes
-f--silent, --quietSuppress most error messages
--reference=RFILEUse RFILE's mode instead of specifying MODE
--preserve-rootDon't recurse on / (default)
--no-preserve-rootAllow recursion on /
--helpDisplay help
--versionOutput version

Permission Modes

Octal Mode

Each digit represents user/group/others: read=4, write=2, execute=1.

OctalPermissionMeaning
755rwxr-xr-xOwner: all; group/others: read+execute
644rw-r--r--Owner: read+write; group/others: read
700rwx------Owner: all; group/others: none
600rw-------Owner: read+write; group/others: none
777rwxrwxrwxEveryone: all (avoid!)
444r--r--r--Everyone: read only
500r-x------Owner: read+execute; group/others: none

Symbolic Mode

Format: [ugoa][+-=][rwxXstugo]

SymbolMeaning
uUser (owner)
gGroup
oOthers
aAll (ugo)
+Add permission
-Remove permission
=Set exact permission
rRead
wWrite
xExecute
XExecute only if file is a directory or already has execute
sSet user or group ID on execution (setuid/setgid)
tSticky bit

Examples

# Make script executable
chmod +x script.sh

# Set standard file permissions
chmod 644 file.txt

# Set standard directory permissions
chmod 755 dir/

# Recursive permission change
chmod -R 755 dir/

# Add execute for directories only (capital X)
chmod -R u=rwX,g=rX,o=rX dir/

# Remove write permission for group and others
chmod go-w file.txt

# Set exact permissions for user, add read for group
chmod u=rwx,g+r file.txt

# Copy permissions from another file
chmod --reference=source.txt target.txt

# Verbose output
chmod -v 644 file.txt

# Set setuid bit
chmod u+s /usr/local/bin/program

# Set sticky bit on directory
chmod +t /tmp/shared/

# Make files read-only
chmod a-w file.txt

Gotchas

  • Never use 777 in production. It gives everyone full access.
  • chmod -R 755 sets execute on ALL files. Use find with -type to differentiate:
    find dir/ -type d -exec chmod 755 {} +
    find dir/ -type f -exec chmod 644 {} +
  • Capital X is crucial for recursive operations: it adds execute only to directories and files that already have execute, avoiding making every file executable.
  • chmod does not follow symlinks by default. The permissions of a symlink itself are typically ignored; the target's permissions matter.
  • Setuid/setgid (chmod u+s, g+s) on scripts is ignored by most modern kernels for security reasons. It only works on compiled binaries.
Repository
flox/floxenvs
Last updated
Created

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.