How to Create a Bash Script for Mass Changes

Collect the data that is needed to be changed., Alright that's neat, but kind of hard to read if you have a lot of 777 permissions in this directory., Now that we have our data, we can start with some basic scripting. , Verify your data for each in...

11 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Collect the data that is needed to be changed.

    Here we will use the "find" command to look for 777 directories under user "whomever." find /home/whomever/public_html
    -type d
    -perm 777 This finds any directories (-type d) in directory /home/whomever/public_html that are 777 permissions (-perm 777).

    You can change this to work with whatever directories you want, permissions you want, etc.
  2. Step 2: Alright that's neat

    Let's make them all go into a file.

    Start with the same command, but we'll add something to make it go into a file we create. find /home/whomever/public_html
    -type d
    -perm 777 > badpermlist What this does is take our query and creates a file called "badpermlist" where all the data will be put. ,, IMPORTANT: the ` ` marks are the ones that are under the ~ key, NOT the apostrophe key. ,, for each in `cat badpermlist`     press
    -enter- do                                         press
    -enter- ll
    -d $each                              press
    -enter- done | more                            press
    -enter- Now all the data that showed up as 777 should now show as
    755. , I hope this helps breakdown some basic concepts for you and helps you on your scripting way!
  3. Step 3: but kind of hard to read if you have a lot of 777 permissions in this directory.

  4. Step 4: Now that we have our data

  5. Step 5: we can start with some basic scripting.

  6. Step 6: Verify your data for each in `cat badpermlist`     press -enter- do                                         press -enter- ll -d $each                              press -enter- done | more                            press -enter This will show your data that is in the file.

  7. Step 7: Change the data for each in `cat badpermlist`     press -enter- do                                         press -enter- chmod 755 $each                   press -enter- done                                     press -enter- Congratulations

  8. Step 8: you just changed all those pesky 777 permissions to 755 like they should be.

  9. Step 9: Verify that the change took place because it is never a bad idea to check your work.

  10. Step 10: Now as you can tell

  11. Step 11: there is a lot of potential to a very simple script like this.

Detailed Guide

Here we will use the "find" command to look for 777 directories under user "whomever." find /home/whomever/public_html
-type d
-perm 777 This finds any directories (-type d) in directory /home/whomever/public_html that are 777 permissions (-perm 777).

You can change this to work with whatever directories you want, permissions you want, etc.

Let's make them all go into a file.

Start with the same command, but we'll add something to make it go into a file we create. find /home/whomever/public_html
-type d
-perm 777 > badpermlist What this does is take our query and creates a file called "badpermlist" where all the data will be put. ,, IMPORTANT: the ` ` marks are the ones that are under the ~ key, NOT the apostrophe key. ,, for each in `cat badpermlist`     press
-enter- do                                         press
-enter- ll
-d $each                              press
-enter- done | more                            press
-enter- Now all the data that showed up as 777 should now show as
755. , I hope this helps breakdown some basic concepts for you and helps you on your scripting way!

About the Author

G

Grace Cook

Dedicated to helping readers learn new skills in crafts and beyond.

82 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: