Bash script Change folder Permissions Recursively

In my post, How to use Bash script Change to folder Permissions Recursively. For example, To change all folder and file under huuphan.com folder.

To list tree file and folder under huuphan.com folder
[root@huupv huupv]# tree huuphan.com/
huuphan.com/
├── a
│   ├── abc.txt
│   └── b
│       └── c
└── K

4 directories, 1 file

To use find command list all file and folder under huuphan.com folder
[root@huupv huupv]# find /home/huupv/huuphan.com -type d -exec ls -ld {} + >chown_folder.txt

To use cat command read chown_folder.txt file
[root@huupv huupv]# cat chown_folder.txt 

The content in chown_folder.txt file file as below:
drwxrwxr-x. 4 huupv huupv 4096 Mar  9 22:38 /home/huupv/huuphan.com
drwxrwxr-x. 3 huupv huupv 4096 Mar  9 22:38 /home/huupv/huuphan.com/a
drwxrwxr-x. 3 huupv huupv 4096 Mar  9 22:37 /home/huupv/huuphan.com/a/b
drwxrwxr-x. 2 huupv huupv 4096 Mar  9 22:37 /home/huupv/huuphan.com/a/b/c
drwxrwxr-x. 2 huupv huupv 4096 Mar  9 22:38 /home/huupv/huuphan.com/K

The bash script Change folder Permissions Recursively
[root@huupv huupv]# cat chown_folder.sh

The content bash script as below:
#!/bin/bash
# Author: HuuPV
while read -r line
do
    a=$(awk '{print $9}')
    chown $1:$2 $a

done < chown_folder.txt

To run bash script as below:
[root@huupv huupv]# ./chown_folder.sh nobody huupv

conclusion
Thought a article, To help you how to change folder and file permissions recursively use bash script.
Bash script Change folder Permissions Recursively


Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install php7 on centos 6