How, from a Terminal, do I make a plain text file and a folder?
2 Answers
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.
-
Just in case someone wonders: Can I open files in TextEdit from the Terminal in Mac OS X? – brasofilo Jun 03 '19 at 00:23
-
@ankii Why the redirect to archive.org? Also, it seems that the edit you approved only fixed some of the broken links :-) – nohillside Jun 25 '20 at 05:54
-
-
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.
-
1Technically,
touchcreates an empty file if the file does not exist, not a text file. – fd0 Oct 13 '18 at 13:21
touch fileis far too brief to serve as an answer... – bmike Dec 31 '15 at 21:33touchis to "change file access and modification times" (fromman touch), unless you mention thattouch filenameonly creates filename if it doesn't already exist. Otherwise it does its primary function. – user3439894 Dec 31 '15 at 22:31