Editing root files (permissions)

Discussion in 'macOS' started by pjrobertson, May 24, 2008.

  1. pjrobertson macrumors 6502a

    Joined:
    Nov 14, 2007
    #1
    Files such as /etc/profile etc. are ones that I want to edit (where you have to be root to edit them)

    I don't want to use vi or pico in terminal, because it doesn't look too user-friendly...


    I know I can use the command to open up TextEdit with root privileges in terminal
    Code:
    sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit <filename>
    but when I addan alias to my bash file
    Code:
    alias edit="sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit"
    and run
    # edit

    it doesn't work (I get told I need permission to save the file after editing.)

    Any ideas?

    I've tried running
    #sudo edit
    but that doesn't work either. ( I get "sudo: edit: command not found")
     
  2. pjrobertson thread starter macrumors 6502a

    Joined:
    Nov 14, 2007
    #2
    I'm guessing the reason it doesn't work is because you can't make an alias that includes 'sudo' in it and you cant use the command

    #sudo alias-name

    are there any alternatives?
     
  3. slu macrumors 68000

    slu

    Joined:
    Sep 15, 2004
    Location:
    Buffalo
    #3
    vi is very easy.

    sudo to root.

    vi /<path>/<filename>

    hit i to go to edit mode.

    make any edits you want.

    hit esc to get out of edit mode.

    type :wq to save and quit vi.

    why are you doing this?
     
  4. pjrobertson thread starter macrumors 6502a

    Joined:
    Nov 14, 2007
    #4
    aaah now that makes vi sound a little easier :p

    I'd just prefer to use Textedit, things like copying / pasting are so much easier.

    I'm just trying to make it easier to edit some system files (I know about screwing up OS X!).
     
  5. slu macrumors 68000

    slu

    Joined:
    Sep 15, 2004
    Location:
    Buffalo
    #5
    Yes, but why are you editing system files? I know you want to, but I don't understand why you would need to.

    You can also copy and paste in terminal by highlighting a word and right-click > copy or paste. The keyboard shortcuts work as well. This is the same as text edit.

    Also, in vi, you before you enter edit mode (before you hit the i), yy will copy the line you are on and p will paste that line after the current line.

    And I forgot to mention that if you change something in vi and want to quit without saving, you hit :q!

    I know you said you know about screwing up OS X, but I think maybe you should become more familiar with terminal and/or vi before you go messing around. But that is just my two cents and I am in no way trying to judge. Good luck.
     
  6. pjrobertson thread starter macrumors 6502a

    Joined:
    Nov 14, 2007
    #6
    I'm pretty familiar with the terminal, and did read up on vi (but gave up!)

    The main reason is that I was changing /etc/profile to include my custom aliases. I know I could have stored them in ~/.bashrc, but the command
    #source .bashrc

    had to be loaded in terminal every time.
     
  7. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    Create a .profile file in your home directory so changes only effect yourself and not other users. There should be no real reason to edit the global files.
     
  8. GotPro macrumors 6502

    Joined:
    Jan 29, 2007
    #8

    Agreed... and without being rude, if you aren't smart enough or don't care enough to learn vi to edit your system files, YOU DON'T KNOW ENOUGH TO BE EDITING YOUR SYSTEM FILES.

    You NEVER, EVER, EVER, EVER edit a system TEXT file with TextEdit or most other GUI text editors... anything from screwed up @ permission additions to invisible spaces can be inserted into the files rendering them, if not useless, with unexplained random results that you will NEVER in a MILLION years be able to track down.


    Again, no offense. But don't muck around with the system internals unless you are ready to learn / know about the tools that were created to muck around with the system internals.

    Case in point. You are ready to edit an inner-working system file, yet you don't have enough knowledge to even know why it won't let you edit it. If you go to terminal, and do a 'ls -l /etc/profile' you'll notice that the permissions are set to READ ONLY for that file, even as root.

    WHICH MEANS that even if you are root user, without explicitly changing the permissions BEFORE you edit the file, you WILL NOT BE ABLE TO SAVE CHANGES TO THE FILE, EVEN LOGGED IN AS THE ROOT USER.

    Again, I'm not slamming on you... just saying that... YOU NEED TO KNOW WHAT YOU ARE DOING BEFORE YOU START MUCKING WITH THE SYSTEM FILES.

    Thats all! :)

    Good Luck.

    And learn vi.
     
  9. Infrared macrumors 68000

    Infrared

    Joined:
    Mar 28, 2007
    #9
    Not true. As root you can write it with ':w!'.
     
  10. pjrobertson thread starter macrumors 6502a

    Joined:
    Nov 14, 2007
    #10
    :D no offence taken


    Cromulent's solution looks like the simplest way to do what I want to do.

    I guess I'm used to having to edit /etc/ files on linux (boot parameters etc.) but should stay away form it on OS X!


    Thanks
     
  11. GotPro macrumors 6502

    Joined:
    Jan 29, 2007
    #11
    Oh My God. That is sooo wrong. Even as root, you shouldn't be able to do that (although it will work, I just tested it) if the rwx permissions FOR root are set to -r- only.

    Or maybe I'm just retarded? :)
     
  12. Infrared macrumors 68000

    Infrared

    Joined:
    Mar 28, 2007
    #12
    Yep. It looks like the permission flags are just ignored as root. E.g.,

    Code:
    sh-3.2# cd /tmp
    sh-3.2# echo hello > abc
    sh-3.2# cat abc
    hello
    sh-3.2# chmod 400 abc
    sh-3.2# ls -l abc
    -r--------  1 root  wheel  6 27 May 13:07 abc
    sh-3.2# echo world >> abc
    sh-3.2# cat abc
    hello
    world
    I'm too retarded to answer that! :)
     

Share This Page