19

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

32

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

you can use find , see below example

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

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

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.