Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Change permissions of every directory in current directory

Terminal - Change permissions of every directory in current directory
find . -type d -exec chmod 755 {} \;
2009-06-07 08:17:06
User: marssi
Functions: chmod find
1
Change permissions of every directory in current directory

"find . -type d -print0 | xargs -0 chmod 755"

thanks masterofdisaster

Alternatives

There are 4 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

find . -type d -exec chmod 755 {} +;

{} +: to let it behave like using xargs

the same command has been posted before

Comment by JesusSuperstar 281 weeks and 5 days ago

Try:

find . -type d -print0 | xargs -0 chmod 755

1. It is much faster of large amounts of files because chmod does not get invoked for every file seperately.

2. And besides null terminating the file name takes care of nasty spaces|quotes|your-favorite-non-printable-characters in file names.

3. Same goes for files:

find . -type f -print0 | xargs -0 chmod 644
Comment by masterofdisaster 281 weeks and 5 days ago

In zsh you can do the same with this command:

chmod 755 **/*(/)

It's fast, efficient and works with all filenames (spaces and anything).

To do the same with plain files:

chmod 644 **/*(.)

For those not familiar with zsh wildcards, this is how the above commands work: "**" is the same as "*", but it works recursively down the directory tree, so you don't have to use the find command. Any wildcard pattern can be followed by a set of flags in parentheses (there must be no space between!): "(/)" restricts the matches to directories only, and "(.)" does the same for plain files. There are many more wildcards and flags; this is just the tip of the iceberg.

Comment by inof 281 weeks and 4 days ago
find . -type d -print0 | xargs -0 chmod 755

+1; xargs is better

Comment by asmoore82 281 weeks and 4 days ago

Actually, koukos was right here -- using "{} +" in a find -exec command tells find to build the command with every matching file /before/ execution, so chmod would only be invoked once (unlike using "{} \;" which tells it to invoke the command once for every file matched)

I have a shared drive here in the office which I occasionally get permission problems with for other users, so I use

find . ! -perm /g=r -exec chmod g+r {} +

a lot: turns on the group readable bit for any files that don't currently have it on, in one invokation of chmod.

Comment by sanmiguel 281 weeks and 3 days ago

Beware, the ^above "zsh" method misses hidden files and folders. While there may be a way around this with zsh's options, why waste the time when `find` is Unix standard? Will zsh also search by perms or times? Will zsh combine search methods? Always pick the right tool for the job; `find` is for *finding*

Comment by asmoore82 281 weeks and 3 days ago
Comment by asmoore82 281 weeks and 3 days ago

^oops :/, excuse me :[

`xargs -0` is _still_ *better*; the "+" is *NOT* Portable.

Comment by asmoore82 281 weeks and 3 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts