Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i want to set sticky bit for all directories in a directory excluding files. is there any wild card to do this?

#sudo chmod g+s /var/www/<WILD_CARD_FOR_ALL_DIRECTORIES>
share|improve this question
up vote 18 down vote accepted

Use */ to match only directories.

chmod g+s /var/www/*/

To match all directories and subdirectories use **/*/ (provided you have globstar enabled in bash):

shopt -s globstar
chmod g+s /var/www/**/*/
share|improve this answer
Works well, but will break as soon the expanded command line length exceeds the command line length limit. -> cyberciti.biz/faq/argument-list-too-long-error-solution – Bonsi Scott Jan 4 '13 at 9:22
yes, I am well aware of that. However, the OP asked for a "wildcard". – dogbane Jan 4 '13 at 9:32
yeah! i asked for wildcard, thanq. – neckTwi Jan 5 '13 at 6:21
i know that he asked for a wildcard-solution. I've only pointed out that it would fail under some circumstance. Other that that, no critc to see here (I#ve commented yet upvoted, because it is a working solution for most cases) ^^ – Bonsi Scott Jan 7 '13 at 18:24

you can use find , see below example

find /var/www/ -type d -exec chmod g+s {} \;
share|improve this answer
This is nice, yet not a wildcard though - but it has the advantage on not failing due to much directories – Bonsi Scott Jan 4 '13 at 9:19
Note that this is recursive by default. If you only want your command applied to the top level you can use the -maxdepth find argument. – Kris Harper Jan 4 '13 at 14:16

This is NOT a wildcard, so I apologize for a non-answer, however...
ls -al |grep ^d | awk '{print$NF}' will list all directories in the current dir, it's up to you to decide if you want to process . and .. or strip them.

echo $(ls -al |grep ^d | awk '{print$NF}') does makes it behave like a wildcard

share|improve this answer
This will break if your files have leading or trailing whitespace, or newlines. – Chris Down Feb 26 '13 at 8:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.