Problem Statement
What does the sticky bit do on a directory?
Explanation
The sticky bit on directories restricts file deletion - only the file owner, directory owner, or root can delete or rename files, even if the directory is world-writable. This prevents users from deleting others' files in shared directories. The classic use case is /tmp directory where all users can create files but shouldn't delete others' files.
Set sticky bit with chmod +t directory or chmod 1777 directory (1 in leading position indicates sticky bit). In ls -l output, sticky bit shows as 't' in others execute position (drwxrwxrwt). If directory isn't executable for others, it shows as 'T' (drwxrwxrwT).
Without sticky bit, anyone with write permission on a directory can delete any file in it regardless of file ownership. This is dangerous for shared directories. The sticky bit ensures that in collaborative spaces like /tmp or /var/tmp, users can only manage their own files, preventing accidental or malicious deletion of others' files.
Practical example: mkdir /shared && chmod 1777 /shared creates a shared directory where everyone can create files, but only owners can delete their files. Understanding sticky bit is essential for managing shared directories securely in multi-user environments.
