Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com

This Blog is protected by DMCA.com

huuphan.com. Powered by Blogger.

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
[[email protected] 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
[[email protected] huupv]# find /home/huupv/huuphan.com -type d -exec ls -ld {} + >chown_folder.txt

To use cat command read chown_folder.txt file
[[email protected] 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
[[email protected] 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:
[[email protected] 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


post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com