# directory and files chmod



## SuperMiguel (Jun 12, 2009)

So i have about 600gb of data.. in which there are alot of directories and alot of files.. Im trying to put this on a ftp server.. So i want to set the permissions on the directories to be 755 and the permission on the files to be 644. So i used:


```
find . -type d -exec chmod 755 {}\;
```
and

```
find . -type f -exec chmod 644 {}\;
```
 
The command for the files seemed to work on the majority of the files.. But the one for directories worked for like 30% of my diretories.. Can you guys recommend another way of doing this.. To make sure "all" my files are set to 644 and "all" my directories are set to 755... Also the folders that are not getting change have a 777 permission. Also im running this command from the main directory


----------



## SirDice (Jun 12, 2009)

Make sure the owner and group are set correctly for those directories. You cannot change permissions on files/directories you do not own.



> Only the owner of a file or the super-user is permitted to change the mode of a file.


See chmod(1).

If you want to change ownership of a complete directory tree use chown with the -R switch.


----------



## SuperMiguel (Jun 12, 2009)

Ran this script and it fixed: 


```
find . -type d -print | while read DIR
do
         chmod 755 "${DIR}"
done

find . -type f -print | while read FILENAME
do
         chmod 644 "${FILENAME}"
done
```


----------



## SirDice (Jun 12, 2009)

Which does exactly the same as the first commands you've posted.


----------



## SuperMiguel (Jun 12, 2009)

well the first command didnt work the second one did.. so not sure why


----------

