How to create a text file and a folder from terminal?

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


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.