How to change file access permission (chmod) recursive |
Introduction: Once I made something wrong (my fault...) and I set chmod 644 for all the files and directories in /var/ftp. And there was 46GB of data. On the server I did not had the Midnight Commander (mc) to repair the damage, so I had to made one line script to restore the rights.
In this example I will use /var/ftp and 755 rights for directories and 644 for files (the default rights).
By using bash scripting:
[root@linuxftp]# cd /var/ftp
[root@linux ftp]# for I in `find -type d` ; do chmod 755 $I ; done [root@linux ftp]# for I in `find -type f` ; do chmod 644 $I ; done |
If you want something more complex (among other things) you can set the deepth of finding (but do not use this script as it is because, probably, your ftp structure is not like my ftp structure):
[root@linux ftp]# cd /var/ftp
[root@linux ftp]# for I in `find -mindepth 1 -maxdepth 3 -type d` ; \ > do chmod 755 $I ; done [root@linux ftp]# for I in `find -mindepth 1 -maxdepth 3 -type f` ; \ > do chmod 644 $I ; done |
By using the mc:
1. Go to into the folder that is in the top of your structure that want to change (ex.: #cd /var/ftp). I will use the /var/ftp as above...;LiNUX Horizon Main Page | LiNUX Horizon Online Shop | LiNUX Horizon Forum
Advertising links: Laptop Notebook | Calculatoare | PDA GPS