Results 1 to 7 of 7

Thread: how to undo chmod -R 755

  1. #1
    Join Date
    Apr 2007
    Beans
    Hidden!

    how to undo chmod -R 755

    A backup script was accidentally run a few directories below where it should have. the chmod -R 755 has affected about 20 website structures that shouldn't have been touched.

    My curiosity now goes to, how can one undo such a change?
    Is it at all possible?

    Is there some way of outputting the current state of file attribs to a file, as say, a daily/weekly cron job?

    The hope with that being that parsing that file, could restore the previous attribs and permissions should something like this happen again.

    Anyone?

  2. #2
    Join Date
    Mar 2006
    Location
    Devon UK
    Beans
    419

    Re: how to undo chmod -R 755

    i dont think there is any way of automatically undoing what u did but for future reference u can use
    Code:
    ls -l /path/to/folder
    to get a listing of files and folders and their current permissions
    In /dev/null no one can hear the kernel panic!
    Don't EVER use sudo rm -rf / . if you don't understand a command check it out first!
    BACK UP YOUR DATA OR YOU WILL LOSE IT!!
    Supergrub - The best thing since sliced bread www.supergrubdisk.org

  3. #3
    Join Date
    Apr 2007
    Beans
    Hidden!

    Re: how to undo chmod -R 755

    I guess I should rephrase my desires for the cron thing.

    I can ls -l to a file for the whole server if need be.
    But, does anyone know of anything already made, or how one would go about making, a script to parse that info out, and use it to re-attrib all files?

    I'm not so good with parsing it back out to something useable.

  4. #4
    Join Date
    Feb 2008
    Beans
    179

    Re: how to undo chmod -R 755

    From what I've read, Linux has no undo. You will have to manually go in and change permissions for all of the files and directories that were changed. Chmod might be able to be run in interactive mode, and if it can, then this would have been a good time to have used it.

  5. #5
    Join Date
    Jul 2007
    Location
    usa: inland northwest
    Beans
    80
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: how to undo chmod -R 755

    Quote Originally Posted by RHAnthony View Post
    I guess I should rephrase my desires for the cron thing.

    I can ls -l to a file for the whole server if need be.
    But, does anyone know of anything already made, or how one would go about making, a script to parse that info out, and use it to re-attrib all files?

    I'm not so good with parsing it back out to something useable.
    I think I know how to do this, although it's probably not the most efficient way.

    (you could combine these steps, but I'm listing them separately for clarity)

    awk '{print $1 " " $8}' < savefile.txt > step1.txt

    (gives you just the 'rwxrwxrwx' and filename; depending on your system type and 'ls' options, you might need to use something other than fields 1 and 8 )

    sed s/^[d-]//g < step1.txt > step2.txt

    (strips the leading 'd' or '-'; maybe stick an 'l' inside the brackets ('[d-l]') if you have links, too)

    sed s/rwx/7/g < step2.txt > step3.txt

    (repeat for s/rw-/6/g, s/r-x/5/g, ... s/---/0/g. This will give you switches for chmod.)

    sed s/^/chmod\ /g < stepn.txt > steplast.txt

    (sticks "chmod " at the beginning of each line; probably could've combined with the first step)

    Now make 'steplast.txt' executable (chmod 500 steplast.txt) and run it. It'll call 'chmod' a couple bazillion times (well, `find . -print | wc -l` times, actually ) so it's probably not the most efficient way to do this, but it should get the job done.


    That's a lot of steps, but if you stick them all in a script (and test it out pretty thoroughly!!) you should be able to make it work.


    Now someone will come along and tell us that there's already a GUI tool in the repositories to do this

  6. #6
    Join Date
    Mar 2006
    Location
    Devon UK
    Beans
    419

    Re: how to undo chmod -R 755

    This wont be of help now but I have done similar things so I created a small app to record/repair permissions so checkout: http://code.google.com/p/perms/ for future use.
    In /dev/null no one can hear the kernel panic!
    Don't EVER use sudo rm -rf / . if you don't understand a command check it out first!
    BACK UP YOUR DATA OR YOU WILL LOSE IT!!
    Supergrub - The best thing since sliced bread www.supergrubdisk.org

  7. #7
    Join Date
    May 2007
    Location
    Phoenix, Arizona USA
    Beans
    2,909
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: how to undo chmod -R 755

    Do you have any backups before the problem? How would this happen with a backup? If your backups are changing your file permissions you should use something else. What if you had to restore? If you have 20 web sites you should have a good incremental backup and you would be up and running in less than an hour.

    -Tim
    www.pcchopshop.net

    Hard to find and obsolete PC and server parts. "If we can't find it, it probably doesn't exist"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •