How, from a Terminal, do I make a plain text file and a folder?

  • 1
    What kind of file? An empty file? A text file? An image? There's not enough information here to really give you a succinct answer. If you can clarify, I'll reopen the question. – Ian C. Dec 31 '15 at 21:11
  • 1
    I suppose touch file is far too brief to serve as an answer... – bmike Dec 31 '15 at 21:33
  • @bmike I'd say yes it's to short, since it could be argued that the primary function of touch is to "change file access and modification times" (from man touch), unless you mention that touch filename only creates filename if it doesn't already exist. Otherwise it does its primary function. – user3439894 Dec 31 '15 at 22:31
  • @IanC sorry, a txt fire and a folder. – Jemoka Jan 1 '16 at 1:54
  • For the record this is standard Unix, so Linux/Unix tutorials are helpful in general. Only major difference is that MacOS filesystems by default are case insensitive. – Thorbjørn Ravn Andersen Oct 13 '18 at 11:19

A directory can be made using the mkdir command. To make a child directory of the current directory it's simply:

mkdir somechild

This will create a directory (shown as a folder in Finder) named somechild.

A text file can be created in a few different ways. The simplest being the echo'ing of text and redirecting it in to a file like so:

echo This is some text > myfile.txt

This will create myfile.txt and its contents will be the string This is some text.

You can also use a command line text editor such as vim or emacs or nano to start a new text file. The following start a new text file and open them in the editor for each of the aforementioned editors:

vim myfile.txt
emacs myfiles.txt
nano myfile.txt

The nano text editor is probably the most new-user-friendly of those three choices.


To create an empty text file, just use:

touch file_name.txt

From man touch: The touch utility sets the modification and access times of a file. If the file does not exist, it is created with default permissions.

  • Technically, touch creates an empty file if the file does not exist, not a text file. – fd0 Oct 13 '18 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .