Linux Basics

What is Sticky Bit in Linux?

Sticky Bit
Sticky Bit

What is Sticky Bit in Linux?

Sticky bit is a flag added to a directory/file to avoid removing/renaming it by any user other than the owner or root. Please check the below scenario:

Create a directory named “grepitout”

mkdir grepitout

Give all the users read-write-execute access to it

chmod 777 grepitout

Check the permission using the command below:

ls -ld grepitout

Output:

drwxrwxrwx 2 grepit grepit 4096 Feb 9 15:43 grepitout

Create different files in the directory as different users (get into the directory using “cd grepitout/”)

Please check the files and the ownership associated with them:

ls -la grepitout/
-rwxrwxrwx 1 grepit grepit 0 Feb 9 15:48 user1
-rwxrwxrwx 1 user1 user1 0 Feb 9 16:11 user1file
-rwxrwxrwx 1 user2 user2 0 Feb 9 16:15 user2file

This means that the user2 can delete/rename files created by user1 and vice versa. Here we can set “Sticky Bit” to the directory using the command below:

chmod +t grepitout

You can check if the sticky bit is successfully added to the directory using the below command:

ls -ld grepitout
drwxrwxrwt 2 grepit grepit 3096 Feb 9 16:19 grepitout

Please notice that “t” added at the end of the permission bit series “drwxrwxrwt”. You can remove the sticky bit using the command below:

chmod -t grepitout

That means +t to add sticky bit and -t to remove. Once the sticky bit is set the owner of the file can only be able to delete/rename the file/directory.

Read More:

If you like the post Understanding top Command and wish to receive more articles from us, please like our FB page: GrepItOut

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments. For more details on our services, please drop us an E-mail at info@grepitout.com

Add Comment

Click here to post a comment

Topics