?
Solved

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

Posted on 2008-06-16
16
Medium Priority
?
570 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
ID: 21797624
use this:
find . -type d -print0 | xargs -0 chmod 755

Open in new window

0
 
LVL 3

Expert Comment

by:pzurowski
ID: 21797645
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
ID: 21797749
For recursive chmod try:

chmod 755 * -R
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Expert Comment

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

Expert Comment

by:Mikkk
ID: 21797950
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
ID: 21798129
What an asker requests and what they really need are quite often two entirely different things.  :)


0
 
LVL 40

Expert Comment

by:omarfarid
ID: 21799220
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
ID: 21799307
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 21799355
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 P.S. earned 2000 total points
ID: 21800703
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
ID: 21801403
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 P.S.
ID: 21811162
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
ID: 21814995
i am scp ' ing from one server to another.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21816473
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
ID: 21817210
Tintin :
How to use rsync ??

can you give me the complete info

Thanks in advance
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21817436
Assuming you have ssh setup, you do

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:
Suggested Courses

839 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