Find the answer to your Linux question:
Results 1 to 6 of 6
Hi Is it possible to change file permissions recursively (let's say to 600) without affecting permissions of the directories where the files are (so they stay 700)? How can it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2005
    Location
    Ljubljana, Slovenia
    Posts
    18

    Change file permissions recursively (but not affecting directories)


    Hi

    Is it possible to change file permissions recursively (let's say to 600) without affecting permissions of the directories where the files are (so they stay 700)? How can it be done?

    Thanks.

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    I've never worried about directories when doing this. Isn't the '7' to added execution rights over '6' which I believe is read write? Anyway to recursively set permissions throughout directories run
    Code:
    chmod -R 600 $filename

  3. #3
    Just Joined!
    Join Date
    Jun 2005
    Location
    Ljubljana, Slovenia
    Posts
    18
    Yes, but still, how to do it?

  4. #4
    Just Joined!
    Join Date
    Oct 2005
    Posts
    1

    How to do it...

    You want to use the -X option with chmod. The man page is a little obtuse:

    +X make a directory or file searchable/executable by everyone
    if it is already searchable/executable by anyone.

    An example:

    Code:
    [foo foo]$ ls -l
    d---------  3 foo users  4096 2005-10-19 10:57 foo_dir/
    ----------  1 foo users 10240 2005-10-11 10:06 foo_file
    
    [foo foo]$ chmod og+X *
    
    [foo foo]$ ls -l
    d-----x--x  3 foo users  4096 2005-10-19 10:57 foo_dir/
    ----------  1 foo users 10240 2005-10-11 10:06 foo_file
    Basically, -X will set 'rx' permissions on directories only. So use chmod -R to effect directories recursively, and use -X to give directories 'rw' permissions, but leave files secure.

  5. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Here is a single command to do what you want:
    Code:
    find . ! -type d -exec chmod 600 {} \;
    Beginning in the current directory and searching recursively, it finds all files that are not directories and performs chmod 600 on them.

  6. #6
    Linux Newbie raghaven.kumar's Avatar
    Join Date
    Mar 2008
    Location
    Bangalore, India
    Posts
    209

    Thumbs up

    Quote Originally Posted by yolabingo View Post
    You want to use the -X option with chmod. The man page is a little obtuse:

    +X make a directory or file searchable/executable by everyone
    if it is already searchable/executable by anyone.

    Basically, -X will set 'rx' permissions on directories only. So use chmod -R to effect directories recursively, and use -X to give directories 'rw' permissions, but leave files secure.
    Thanks yolabingo, after three years of exp in linux i knew that one can set permissions for folder using 'X'
    Franly Speaking, you passed over a tiny bit of magic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •