OS X: Easily edit hidden configuration files with TextEdit

In OS X, hidden files (those starting with a period like .profile or .bashrc) can be a challenge to edit because they are, well, hidden and don’t show up in Finder windows. While there are tricks to make hidden files visible in Finder windows, I prefer to keep my hidden files hidden. I also prefer to edit them using vi, but I know that many folks are likely to think ‘six’ instead of ‘editor’ when presented with vi. What follows is a simple way to edit a hidden file using TextEdit without making any changes to the system.

When confronted with the task of editing your .profile file, there are several options. For the seasoned veteran, editing this file is simply a matter of dropping to a shell, editing in vi, and :wq’ing. There is the pico editor which, for a command line editor, is a little friendlier than vi. For the majority of users, editing a text file is warmer and fuzzier using a GUI text editor like TextEdit.

The problem is that files starting with a period are hidden from listings in the Finder windows, so trying to find a hidden file to open using TextEdit will not get you very far. While many third party editors provide options for opening hidden files, if you don’t have one installed, you can easily open these hidden files using TextEdit which is a part of OS X.

To open your .profile file, for example, start the Terminal application (searching for ‘terminal’ using Spotlight and clicking on the Terminal application is an easy way to do this). Since Terminal will put you in your home directory by default and .profile is in your home directory, you can edit .profile simply by typing:

open .profile

If the file you want to edit is in another directory, you’ll need to cd into that directory first or specify the full path name in front of the filename.

The open command used above uses the same mechanism to open a file using a default application that the Finder does when clicking on a file. If for some reason the default application for the file you are trying to edit has changed to something that doesn’t work for editing, you can force open to use TextEdit by adding the -a option:

open -a TextEdit .profile

Make your changes to the file and save it and you’re done. One compulsory note of caution: hidden files are often hidden for a reason. They tend to hold configuration information that, if incorrectly changed, could cause one or more applications to misbehave. Tread lightly and make backups before changing.


About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

15 Responses to “OS X: Easily edit hidden configuration files with TextEdit”

  1. October 19, 2008 at 8:33 pm, fin13 said:

    Thanks for this! This is really helpful for newbies that are interested in learning new things.
    I do have a question. I can’t find a .profile file in my user. I am running Leopard and I have looked every where for the file. I have managed to look at all the hidden files but no luck.

    Any suggestions


    • October 20, 2008 at 1:44 pm, Quinn McHenry said:

      Try looking for .bash_profile in your home directory (/Users/yourusername/.bash_profile). In my Leopard install, .bash_profile is used. I don’t have a Tiger (version 10.4) installation around to check, but I suspect this may have changed in Leopard. I have both files in my home directory, but I checked and only .bash_profile is used when a shell starts.

      It isn’t a problem if the file doesn’t exist. You can create the file in your home directory and it will work. To make sure that it is working, you can place a temporary echo command in the file, something like:

      echo “running .bash_profile!”

      When you run the Terminal app to start a shell, you should see that text printed out.


      • January 16, 2009 at 9:43 am, Aron Grinshtein said:

        Thanks I was trying to set up RoR using Dan Benjamins install and you helped me figure out how to find the .profile file. Thanks.


  2. January 28, 2010 at 6:49 am, Ari Salomon said:

    great article. i used this to edit my hosts file:
    open /private/etc/hosts

    except it won’t let me save. i expected textedit to ask me for my password on saving but it simply says I’m not authorized and won’t let me save.


    • November 18, 2010 at 9:26 pm, Tatankisima said:

      Use sudo (sudo open -a TextEdit /private/etc/hosts )


  3. November 18, 2010 at 11:52 pm, ari salomon said:

    when i tried

    sudo open -a TextEdit /private/etc/hosts
    it still would not let me save
    “the document “hosts” could not be saved”


    • February 12, 2011 at 7:00 pm, Pedja said:

      Hi Ari, did you solve this? I have the same problem. TextEdit wont let me save cause it says that I don´t have auctorisation to save. How to do?


  4. December 10, 2010 at 11:29 pm, OT said:

    Hi Guys,

    Can someone help me out? I added the JAVA_HOME, DERBY_HOME and other variables for my needs, changed and saved the .profile on my OSX 10.6.

    In the current terminal session everything works OK. I can verify the variables by echo $JAVA_HOME etc. and work with the stuff.

    But when I close the terminal or open new terminal window I have to manually reload the profile with . ./.profile command to make it work.

    How do I reload the profile automatically for each session?



  5. February 16, 2011 at 11:26 am, Haris said:

    Editing your hosts file…

    1. open up finder.
    2. go/go to folder & write /etc
    3. copy a hosts file to your desktop
    4. copy it again for backup purposes
    5. open the hosts file and edit it in TextEdit and save the file
    6. drag and drop file into /etc directory and replace the old one
    7. just keep your backup hosts file in case something goes wrong so that you can revert to default settings

    I hope this helps :)


  6. May 20, 2011 at 7:55 pm, mkram0 said:

     To edit your hosts file: (i haven’t tried it, but should work)

    cd /private/etc/
    ls -a -l

    (it will list all files including its permissions)

    chmod 777 hosts
    (if it does not work, try sudo chmod 777 hosts)
    open -a TextEdit hosts

    (edit the file, save)

    (now revert back to the permissions that were listed above when you did ls -a -l)
    so chmod PERMISSION hosts
    if the permission is like -rw-r–r– then use quotes chmod “-rw-r–r–” hosts.



  7. July 23, 2011 at 3:27 pm, Andrius Putna said:

    Does anyone know how to solve this?


  8. July 26, 2011 at 2:39 pm, Gogo Xa said:

    It’s helpful. XD


  9. November 03, 2012 at 6:44 pm, Eran Magen said:

    Thank you so much. A total stranger is grateful to you. You helped me solve a problem that seems very important in my own little world. :-)


  10. June 06, 2013 at 5:19 am, gaurav varshney said:

    how can i solve it if am send textedit file to window operating system its show all text in single row …????


  11. August 05, 2013 at 3:58 am, Martin Malmqvist said:

    You can also open TextEdit and open a file from the file browser. Just press shift+cmd+. and the hidden files will show.



Leave a Reply