Results 1 to 6 of 6

Thread: chmod Recursively all directories to 755 and files to 646

  1. #1
    Senior Member vamsi's Avatar
    Join Date
    Nov 2009
    Location
    Bangalore / India
    Posts
    263
    Thanks
    138
    Thanked 14 Times in 12 Posts
    Rep Power
    6

    Default chmod Recursively all directories to 755 and files to 646

    Hi guys..
    How to
    chmod Recursively all directories to 755 and files to 646 at once.

    thanks
    shebangs

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 808 Times in 511 Posts
    Rep Power
    10

    Default

    At once not possible but one by one you can set it up:

    Code:
    find -type d -print0 | xargs -0 -I {} chmod 755 {}
    find -type f -print0 | xargs -0 -I {} chmod 646 {}
    type -d == Dirs
    type -f == Files
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. The Following User Says Thank You to nixcraft For This Useful Post:

    vamsi (30th March 2010)

  4. #3
    Senior Member
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    0
    Thanked 33 Times in 29 Posts
    Rep Power
    12

    Default

    bash 4.0

    Code:
    shopt -s globstar
    for file in **
    do
      if [ -d "$file" ]; then
          chmod 755 "$file"
      elif [ -f "$file" ];then
          chmod 646 "$file"
      fi
     done
    using find

    Code:
    find /path | while read -r FILE
    do
      [ -d "$FILE" ] && chmod 755 "$FILE"
      [ -f "$FILE" ] && chmod 646 "$FILE"
    done
    Last edited by ghostdog74; 30th March 2010 at 06:14 PM.

  5. The Following User Says Thank You to ghostdog74 For This Useful Post:

    vamsi (30th March 2010)

  6. #4
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 808 Times in 511 Posts
    Rep Power
    10

    Default

    Quote Originally Posted by ghostdog74 View Post
    bash 4.0

    Code:
    for file in **
    do
      if [ -d "$file" ]; then
          chmod 755 "$file"
      elif [ -f "$file" ];then
          chmod 646 "$file"
      fi
     done
    I think this will not go into subdir like find command does. Also it may fail when there are too many files. I don't have bash 4 man page installed here but I'm now going to get more info via gnu.org.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  7. #5
    Senior Member vamsi's Avatar
    Join Date
    Nov 2009
    Location
    Bangalore / India
    Posts
    263
    Thanks
    138
    Thanked 14 Times in 12 Posts
    Rep Power
    6

    Default

    Hi , how about

    Code:
    find . -type f -exec chmod 644 {} \;
    shebangs

  8. #6
    Senior Member
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    0
    Thanked 33 Times in 29 Posts
    Rep Power
    12

    Default

    Quote Originally Posted by nixcraft View Post
    I think this will not go into subdir like find command does. Also it may fail when there are too many files. I don't have bash 4 man page installed here but I'm now going to get more info via gnu.org.
    it will, if globstar is set , which i forgot to include

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Linux Recursively Delete Subdirectories
    By raj in forum Linux software
    Replies: 0
    Last Post: 22nd April 2008, 01:50 AM
  2. Shell script to restructure folders recursively
    By kalt in forum Shell scripting
    Replies: 2
    Last Post: 26th October 2007, 12:47 AM
  3. Replies: 0
    Last Post: 5th June 2007, 03:03 AM
  4. Linux list directories and files
    By raj in forum Getting started tutorials
    Replies: 0
    Last Post: 5th May 2007, 01:05 AM
  5. UNIX ls only directories (display only dirs and no files)
    By chiku in forum Solaris/OpenSolaris
    Replies: 1
    Last Post: 21st October 2006, 12:27 AM

Tags for this Thread

Posting Permissions

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