Koozali.org: home of the SME Server

Great script!!! Chmod -R files 644 and directory 755

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Great script!!! Chmod -R files 644 and directory 755
« on: February 04, 2006, 08:34:27 AM »
Long time searching this script, and I found it!! :-D
The author is: http://bsd-crew.de/index.php/Chmod-Script_mit_Directory_und_File_Unterscheidung
With this script you can change recursively files and directorys to any diferent permission.

Quote

Usage: chmodr fff ddd [pfad]
 fff  ... chmod argument for files (644)
 ddd  ... chmod argument for direcories (755)
 pfad ... nothing for current directory
Example: chmodr 644 755 for currently directory
or
chmod 644 755 /home/e-smith/files/ibays/Primary/html/store for specyfic directory.
Ofcourse, you can chmodr 664 777, etc

Make this script with mcedit and save as "chmodr". Open "mcedit, and paste the code with "shift+insert". Save with F2. Change owner to root.root and chmoded to 755. Then copy to /usr/bin directory.

Code: [Select]
#!/bin/sh
# recursive chmod with arguments for files and directories
# save internal field separator
IFS_save=$IFS
# set internal field separator, thx to matthias
IFS=$'
'
# read arguments
chmodf=$1 # chmod for files
chmodd=$2 # chmod for directories
dir=$3    # start directory
# test for arguments $1 and $2
if [ -z "$chmodf" -o -z "$chmodd" ]
then
 echo "Usage: `basename $0` fff ddd [pfad]"
 echo " fff  ... chmod argument for files (644)"
 echo " ddd  ... chmod argument for direcories (755)"
 echo " pfad ... nothing for current directory"
 exit
fi
# if no start directory, use current directory
if [ -z "$dir" ]
then
 dir="."
fi
# "\$x='$x'"
# find backwards all files and directories
for file in `find "$dir" -name "*"`
 do
# debug print
# echo "$file"
if [ -d $file ] # directory
 then
# chmod
  chmod $chmodd $file
  elif [ -e $file ] # file
  then
# chmod
  chmod $chmodf $file
  else
  echo "error: $file"
fi
  done

#set back internal field separator
IFS=$IFS_sav




Enjoy
Normando

Offline m

  • *****
  • 276
  • +0/-0
  • Peet
Great script!!! Chmod -R files 644 and directory 755
« Reply #1 on: August 12, 2007, 03:48:02 PM »
These two lines
Code: [Select]
find pfad -type f -print0 | xargs -0 chmod fff
find pfad -type d -print0 | xargs -0 chmod ddd

do the same.

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Re: Great script!!! Chmod -R files 644 and directory 755
« Reply #2 on: August 14, 2007, 04:10:25 PM »
Very good mweinber

Thank you