Command Line: Add Write Permissions to All Files and Folders

chmod -R g+w *This is a tricky one.

Plenty of people are experts at command line wizardry in the Linux/UNIX/*nix world, and I'd say I'm pretty comfortable with it. Anything you want to do, there's usually some uber-command that does everything in one line, probably using the -exec option, it just requires some searching and a little trial and error (with caution).

But here's one I've had trouble with. We had a directory that had mixed permissions. Specifically, the user and group were set wrong, and the permissions were set to user-write only, or rw-r--r--. I wanted to change the user and group, and set the permissions to rw-rw-r--, so that the group can write as well.

So, the first problem wasn't that bad. I can use chown with the -R flag (recursive) to change to owner. So the first command looked like this:

chown -R user *

Then, the group can be similarly changed with the chgrp command:

chgrp -R group *

I might have needed to run one extra set of commands to catch any files that start with a dot (.), since they'll be ignored by the *.

Now, the tricky part. I can use chmod to change the file permissions. The thing is, files need rw-rw-r-- (664), but directories need rwxrwx-r-x (775). I can't just run chmod -R 664 * because that would mess up directories.

So, the first solution is a little clunkly...

You could use find with the -exec option. You'd have to run two commands, and here's what they look like:

find ./ -type f -exec chmod 664 {} \;
find ./ -type d -exec chmod 775 {} \;

So, to break this down, I'm using the find command on the current directory. -type f means I'm looking for files of type "file". So, it will only return files, not directories. Then I use the -exec option to run the chmod command. The {} are where the replacement goes in, and the \; is just standard syntax. The second command uses -type d, which searches only directories and excludes files.

It works, but there's actually a shorter, one-line command to do both operations. Turns out, chmod can take the octal values (000-777), or it can use "symbolic mode". Using this mod, 'a', 'u', 'g', 'o' stand for 'all', 'user', 'group', 'other', respectively, and permissions are added or taken away using plus (+) and minus (-).

This makes my command really simple. All I want to do is add write permissions for groups on all files and directories. Assuming files currently have a permission of rw-r--r-- (644), and directories have a permission of rwx-r-x-r-x (755), all I have to do is run this command:

chmod -R g+w *

g+w translates to "grant the group write permissions".

And that's it!

P.S. If this keeps happening (as it does to me), it may be a good idea to set the umask variable in your account profile. umask works a little weird, there's an article explaining it here, but the value I would need to add for 664 and 775 permissions by default is this:

umask 002

 

Comments

Isam's picture

Thanks a lot, this was very helpful

get youtube subscribers's picture

Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work.
free youtube views

get youtube subscribers's picture

I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
youtube subscribers

Peter's picture

Software Tailor have been very good to us. They're always there when we need them - to answer implementation questions and provide customer support.
Please find Software Development

john joseph palassery's picture

This is a very good article that you have posted here in this page. I really like the way the details are given n this page. The explanations to the algorithm are given in a very clear manner.
Microsoft problems

wallens's picture

Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks
pou hack
hill climb racing cheats

james's picture

I don t have the time at the moment to fully read your site but I have bookmarked it and also add your RSS feeds. I will be back in a day or two. thanks for a great site google

Anonymous's picture

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
Loft conversions South London

sepatu vans's picture

It's a great pleasure reading your post.It's full of information I am looking for and I love to post a comment that “The content of your post is awesome” Great work! sepatu vans original celana chino

irwan's picture

Programming! Irwan like this! ;)

Ridwan's picture

Desain website http://www.wesjones.net/ benar-benar menarik; walaupun tampilannya sederhana namun mata tidak bosan membaca tulisan-tulisan di blog ini

yilky's picture

I absolutely getting a charge out of every tad bit of it and I have you bookmarked to look at new stuff you weblog post.warframe interception missions

Active-Domain's picture

I truly appreciate this topic you've got going ahead in your website page. What is the name of the format incidentally. Active-Domain

gratuit minecraft's picture

I like your article, you're brilliant which makes them, I read it properly.Glad to going by your site.great article and great site.venus factor diet

wallens's picture

You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!.
gain twitter followers
facebook like hack

james's picture

I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. clash of clans cheats | hill climb racing cheats

bestproducts's picture

Nice article, simple website.. Great combination.. Like it very much,, how to cure a yeast infection | how to make your boobs bigger | how to grow taller

Anonymous's picture

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great.
showbiz news

rai2014's picture

Interesting topic shown here, i am now working on it regularly here and would say keep the future posts like this continuously.
Guar korma and Microlam roasted korma

hilky's picture

I was searching for this sort of data and appreciated perusing this one. Bikini Body Workout Movement

ram14's picture

Year 2013 has been quite eventful. SRSG also witnessed events and evolved in terms of business verticals, technologies, people and processes.
Apple product dealers in Guwahati
AKG Microphones dealers
Mobile broadcasting in india
Turnkey TV Channel Solutions

hilky's picture

I am so excited I discovered your site while I was skimming I've been searching for books of this nature for a really long time. Metabolic Cooking

yilky's picture

When i unite with the update. it gives back a message saying that there are no elements on the chose site. athomeworkoutsforwomen.wordpress.com

gratuit minecraft's picture

I have bookmarked this page for future use.Keep blogging.I'd be extremely thankful in the event that You Could expound a smidgen more. Storesea pharmacy modafinil 200mg

celen's picture

This is an awesome post. Just one of the very best post I've ever seen. What a really good and awesome post. Keep up your work on articles. http://fbhackapp.com/

yilky's picture

Truly decent post. I truly appreciated the quality data you offer to your guests for this site.xbox live codes free

samsellloyd's picture

Thanks for the nice post. I am expecting some different idea from your side. You always represent some new thought in your post.
buy youtube subscribers from http://socialplease.com Thanks :)

Tahubulat's picture

Orang yang kuat hatinya, Bukan mereka yang tidak pernah menangis, Melainkan Orang yang tetap tegar ketika http://cakrawalasehat.blogspot.com/ banyak Orang menyakitinya.

rajaseo's picture

I'm really glad and impressed on the information posted on this site. It helped me understand different topics
celana jeans murah -
celana chino murah -
tas kulit asli -
dompet kulit asli -
ikat pinggang kulit asli -
sepatu kulit online -
tas ransel murah

gratuit minecraft's picture

I like the important information you give in your articles. I'll bookmark your weblog and check again here routinely. Active Registrar

gratuit minecraft's picture

It advises me that I need to acquire more structure to my blogging. Your online journal is extremely fascinating. www.beaconcom.sg

Lina Rose's picture

Home based open door patrons see the same old exhausting pitches for a long time. Indeed the substance devils can transform the online domain into a nap fest. Blog entry. Article. Tweet Links. Rehash. Exhausting! Be cunning. No compelling reason to realize totally new possibilities. Simply think. Place thought into your web promoting battle. Be patient. It requires some investment to think. Quit hurrying. Don't become involved with the numbers diversion. You work with individuals, not numbers. example statement of purpose for graduate school

Tas Plaza's picture

Bagus sekali informasi-nya, saya menginfokan kepada anda yang sedang mencari tas, carilah di tasplaza.com saja..

teiaon's picture

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work.You has really helped a lot of people who visit blog and provide them useful Fifa 15 PS3 Coins

gratuit minecraft's picture

I need to say that this article is amazing, awesome composed and accompany every single critical data. I'd like to see more posts like this. pawn news

High School Diploma Online's picture

Good stuff you have posted thank you.

lafsei's picture

We have best online writing services and best content writing tips are also. So that I am so much interested to get information from your blog write my paper and blog content. So that I am very happy to use your services and blog providing the tips are also.

habib's picture
iklancs's picture

Segala macam link anda bisa anda taruh di sini Iklancs

lafeo's picture

Summon line interfaces to machine working frameworks are less generally utilized by easygoing machine clients, who support graphical client interfaces. Charge line interfaces are regularly favored by more developed machine clients, as they frequently give a more succinct and compelling intends to control a project or working framework.
online paraphrase

lafseo's picture

A document organizer is a sort of envelope that holds detached papers together for association and assurance. Record organizers typically comprise of a sheet of substantial paper stock or other dainty, yet firm, material which is collapsed down the middle, and are utilized to keep paper archives.
seo

aliceseo's picture

I am really impressed with your efforts and really pleased to visit this post.I definitely appreciated every bit of it and I have you book-marked to look at new information in your web site. Pnematic Tubes

70-410's picture

In modern age Man has considered money as bench mark to assess others. In my opinion this bench mark to evaluate others has brought forward many unsocial problems in our society. As God has put greed as an ingredient while he created Man, this ingredient drives many of us very crazy to gain more & more wealth & money. This urge to get more by ethical & unethical means has brought high rate of various crimes into existence. In this race of money & wealth we have forgotten our family values. I have personally witnessed families breaking up due to wealth. People killing their loved ones for wealth. Children putting their parents into old homes as they are of no use for them. The parents who brought them into this world, the mother who kept them in her body for nine months, the father who worked like a robot to give children the best of their future. They are put into worse conditions like garbage. This makes me sick to my stomach.

aauw-daw's picture

It is really a nice and useful piece of information. I am glad that you shared this helpful information with us. Please stay us up to date like this. Thank you for sharing.

Eugene Bennett's picture

Misunderstanding is what when we learn something according to our own mentality level. Misunderstanding is when we take and insist others to think about things in which we think. Misunderstanding is to make some experiment and if it will successful because of any reason then do believe in it blindly. The high quality custom papaer writers are the best in their writing to help and guide the students.

GED Online's picture

Wonderful post i have got here keep it up.

Ambercarl's picture

I like this post. It's quite unusual and innovative. Writer might be really gorgeous. Someone could easily claim that he is a genius. 
http://www.booksharmexcursions.com

Carl's picture

Great work! That is the kind of info that are meant to be shared across the internet. Disgrace on the seek engines for tamsulosin effect on psa not positioning this put up higher! Come on over and consult with my site . Thank you =)

Pages

Add new comment