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>

3 Answers 3


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/**/*/
  • 2
    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 Jan 4, 2013 at 9:22
  • 1
    yes, I am well aware of that. However, the OP asked for a "wildcard".
    – dogbane
    Jan 4, 2013 at 9:32
  • yeah! i asked for wildcard, thanq.
    – Necktwi
    Jan 5, 2013 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) ^^ Jan 7, 2013 at 18:24

you can use find , see below example

find /var/www/ -type d -exec chmod g+s {} \;
  • 3
    This is nice, yet not a wildcard though - but it has the advantage on not failing due to much directories Jan 4, 2013 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. Jan 4, 2013 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

  • This will break if your files have leading or trailing whitespace, or newlines.
    – Chris Down
    Feb 26, 2013 at 8:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .