Solved

change the permission on a directory (all the files in the directory)

Posted on 2008-06-16
16
524 Views
Last Modified: 2013-12-27
Hai !
       I know to change the permission for a file using chmod xxx on file or directory.

Now my question is i have a directory and with in the directory i have lots of sub-directories and files.

i want to change the permission to 775 to all the contents at once. How to do it ?

chmod 755 xxxx
0
Comment
Question by:vishali_vishu
  • 4
  • 3
  • 3
  • +3
16 Comments
 
LVL 3

Expert Comment

by:pzurowski
Comment Utility
use this:
find . -type d -print0 | xargs -0 chmod 755

Open in new window

0
 
LVL 3

Expert Comment

by:pzurowski
Comment Utility
in similar way, you can change attributes of all files -- instead of letter "d" use letter "f".

If you want other directory, insted dot enter directory of your choice
0
 
LVL 8

Expert Comment

by:Mikkk
Comment Utility
For recursive chmod try:

chmod 755 * -R
0
 
LVL 3

Expert Comment

by:pzurowski
Comment Utility
@Mikkk this one will change permission of all files as side-effect
0
 
LVL 8

Expert Comment

by:Mikkk
Comment Utility
True. That is what  vishali_vishu wants. "i want to change the permission to 775 to all the contents at once"
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
What an asker requests and what they really need are quite often two entirely different things.  :)


0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
I think Mikkk's solution is the answer to the question since it meets the requirement "i want to change the permission to 775 to all the contents at once"
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
omarfarid.  I'm not disputing that Mikkk has given a solution based on the request, but the issue is that changing permissions on *all* files/directories to the same permissions is very rarely required.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
I agree with you and I already sow the two solutions one for the the question, but wanted to say that both the title and the question body shows that this is what is required. I am not objecting to your comment and it could turn that what the asker wants is not what the answers gave.
0
 
LVL 16

Accepted Solution

by:
Hanno Schröder earned 500 total points
Comment Utility
a) Change permisson to 755 on directories only:
    find . -type d -exec chmod 755 {} \;
b) Change permission to 644 on all files:
    find . -type f -exec chmod 644 {} \;

Using
   chmod -R 755 *
does in fact give the right answer to the original question, but Tintin
tries to give some more information looking behind the original Q of
the asker.
The same way, I am usually trying to answer but make also sure the
asker gets the required information to understand what he might be
expecting incorrectly or what would be "best practice".

If there are only (!) executable files in these directories, changing
their mode to 755 may make sense, too.
0
 
LVL 1

Author Comment

by:vishali_vishu
Comment Utility
Thanks a lot....

This one workout  :

chmod -R 755 *


Actually i have all the executables on one server and i am copying them to another backup server.
so i need to give the executable permissions to all the contents in the directory ( files as well as sub directories and even the contents with in sub - directories ).



0
 
LVL 16

Expert Comment

by:Hanno Schröder
Comment Utility
How do you copy?
copying from one system to another transferring permissions
can be accomplished with either
  cp -pr  <source-dir>  <target-dir>
or
  cd <target-dir>
  ( cd <source-dir> ; tar cf - . ) | tar xf -
Note: To watch the copy progress, change xf to xvf
0
 
LVL 1

Author Comment

by:vishali_vishu
Comment Utility
i am scp ' ing from one server to another.
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
If you use rsync, you'd have the exact same permissions (and would probably be a lot quicker as well)
0
 
LVL 1

Author Comment

by:vishali_vishu
Comment Utility
Tintin :
How to use rsync ??

can you give me the complete info

Thanks in advance
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Assuming you have ssh setup, you do

rsync -av -e ssh /source/dir/* remote-server:/dest/dir
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now