Permissions – How to Find All Files and Directories Without Sticky Bit

findpermissionssticky-bit

how do you find all files and directories without sticky bit?

I have a bunch of old files that I need to delete so I use: find . -mtime +3 -a \( -type f -o -type d \)

But then this find command will still find files with sticky bit permission: drwxrwxrwt

I want to make sure my find expressions does not find these files. Or … should I just be lazy and ignore "operation not permitted" errors (maybe this is the sticky bit's intent/purpose… let's you delete files without worrying about accidently deleting files that you need)?

Best Answer

If you want to find stuff with sticky bit set, you need -perm parameter, version with slash checks for any of the bits - but we're only going to supply one bit, that is the octal version of sticky bit:

find . -perm /1000

Now you want to do the reverse, so negate the condition:

find . \! -perm /1000

And adjusted for your command:

find . -mtime +3 -a \( -type f -o -type d \) \! -perm /1000