Find the answer to your Linux question:
Results 1 to 6 of 6
I would like to make a bash script that changes permissions recursively, so as to ease the transition between umasks. Basically, by default the umask is 022, but I prefer ...
  1. #1
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132

    Changing Permissions Recursively

    I would like to make a bash script that changes permissions recursively, so as to ease the transition between umasks.
    Basically, by default the umask is 022, but I prefer it 077 for my own home directory. I can change it easily enough, but all the files created before I changed it retain a umask of 022.

    I would like to be able to change all the files to a permission of 600, and all directories to a permission of 700.

    How would I do this?

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Use the 'find' command:

    Code:
    find /path/to/home -type f -exec chmod 600 {} \;
    find /path/to/home -type d -exec chmod 700 {} \;

  3. #3
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    Ah, nice! I didn't think of that.

  4. #4
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    Just wondering, what does the:
    {} \;
    do?

  5. #5
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    The format of find's -exec option is:

    -exec command ;

    Whenever the string {} is seen within command it is replaced by the current file name being processed.

    The semi-colon ( ; ) has to be escaped with the backslash (\) to keep the shell from treating it as the end of the find command.

    Look at the find manpage (# man find) for details.

  6. #6
    Linux Newbie egan's Avatar
    Join Date
    Feb 2009
    Location
    Mountain View, CA
    Posts
    132
    Ah, that is what I figured, but I just wanted to make sure.

Posting Permissions

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