Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-16
16
Medium Priority
?
565 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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'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.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

610 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