Solved

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

Posted on 2008-06-16
16
540 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 Schröder earned 500 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 Schröder
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

803 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