Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I work a lot at the command line in a Terminal and would like to start a text editor on a certain file. I'm from Linux Land and normally use kwrite or gedit from a bash shell. Trying to find the Mac equivalent, as a guess, tried

user> textedit somefile.txt


user> texteditor somefile.txt


user> TextEditor somefile.txt

and other variations. I can't seem to find the proper name of the text editor app. (No, vi isn't to my liking.) Oddly, the guy at an Apple store didn't know this.

share|improve this question
Both Nathan and mipadi provide answers, but I think they're only partial answers, so I added one. I'm not sure if it would have been better to combine their responses somehow, and if so, how to have done that. – Viktor Haag Jun 27 '11 at 19:07
@Viktor it generally isn't good to re-post things that people have already said, and exact duplicates are removed. Since you had something to add, good ways to go would be an answer saying "In addition to Nathan and mipadi's techniques...", or comments on those answers with your addendums. What you've done here is okay, but not exactly a 'best practice'. Thanks for asking; now you know for the future :-). – Nathan Greenstein Jun 27 '11 at 21:27
up vote 60 down vote accepted

Here are some possible answers, all using the 'open' command-line utility.

The -a option means "open the file argument with the named application":

open -a TextEdit file.txt

The -e option means "open the file argument with the TextEdit application":

open -e file.txt

The -t option means "open the file with the default application for editing text files, as determined via LaunchServices". By default, this will be /Applications/; however, it's possible for this setting to get overridden:

open -t file.txt

Finally, any file that's of the "text" type will get opened by the application bound to the text type if you just say open file.txt. You can use the "file" command to reveal what the operating system thinks the file type is: file file.txt. So, for example, if you renamed "file.txt" to just "textfile" then open textfile would still open it in the default text-file editing application, as long as file textfile still thought that "textfile" was actually a text file.

A short 'help' file on open can be found by running

open --help

Or you can read the whole manual with

man open
share|improve this answer
I put this into my .bash_profile: "alias o='open -a Sublime\ Text\ 2'" and then I can simply type at the command prompt: "o text.txt". It's very easy on the fingers ;) – cmroanirgo Jul 15 '14 at 2:57
open is the only 'right' way to do this. – CousinCocaine Oct 9 '14 at 9:40

The default text editor is TextEdit. You can open a text file in there by using open -a:

$ open -a TextEdit hi.txt

If you want to use another app, just put it's name in, like this:

$ open -a Coda index.html
share|improve this answer

There are two ways:

If your default text editor is TextEdit, you can simply use

open -t file.txt

to open it in TextEditor.

If your default text editor is not TextEdit, and you want to open it in TextEdit specifically, you can use

/Applications/ file.txt

Either of those can be made an alias in your shell config file, of course.

share|improve this answer
Notice that I'm not sure that the convention of passing the file name argument directly to the application's name on the command line may not work for all applications. Only applications that are built to accept filenames on the command line as valid arguments for opening will work this way. I think that the more general open command uses a more thorough method to get an application to "open" the file argument passed to the open command (i.e. it depends on the same functionality by which the Finder's "double click to open" action works). – Viktor Haag Jun 27 '11 at 19:10
@Viktor Haag: Both of those will work with TextEdit. – mipadi Jun 27 '11 at 19:18

If you search for a comfortable way with more "linux feel" add something like the following to your ~/.profile:

alias textmate='open -a TextMate'


alias textedit='open -a TextEdit'

depending on your editors.

share|improve this answer
Although .profile works, .bash_profile is more common on OS X. – CousinCocaine Oct 9 '14 at 9:41

If you already started to write in terminal and you want to continue on your favorite editor you can press ctrl+X, ctrl+E and continue working in emacs or your default bash editor.

If you want to change the default editor, change the environment variable EDITOR to your favorite one:

EDITOR=vim;export EDITOR
share|improve this answer

See if you have the vim editor, I didn't even realize my terminal could use it.


user> vimtutor 

to figure out its controls.

You can edit files pretty well with it. The syntax looks something like:

user> vim foo.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.