How would I create a
.txt file, customize what it says, and open it. All with Terminal. [OSX Yosemite]
For personal use (ie, not in scripts) I recommend
nano. A somewhat controversial choice among frequent terminal users, but unlike
nano isn't modal (ie, it's going to work the way you would expect a graphical text editor to work). Using
nano will let you perform all three actions (create the file, edit the text, and view it) all with one command. Your syntax will be
nano /path/to/file.txt. Of course, you can also use
vim, but if you choose to you definitely need to read about how first (if you're coming from a graphical background you've almost certainly never even heard of a modal editor before).
To create the file without opening the editor, use
touch. This creates an empty file. The syntax would be
touch /path/to/file.txt. If you need to make a new folder to put the file in, use
mkdir. The syntax is
To view the file without opening the editor, use
cat /path/to/file.txt) if it's short. This will just print the whole file to the terminal. If the file is longer, use
more, which will each allow some navigation (eg, they'll let you scroll). By this point, you can probably guess the syntax. They're very similar commands: more or less,
more, but more (
less lets you scroll backward,
more does not). Of course, you can also just look at the file in
nano and then not write any changes.
Finally, if you
cd into your working directory first, you can just refer to the file with its name without the path (eg,
nano file.txt, and similar for the other commands I mentioned). It stands for "current directory" and the syntax is
Hope this helps!
There are several text editors that come with terminal on OS X. VI, emacs, and nano are probably the most well known.
man vi, and
man emacs or just googling those three items as well as 'OS X Terminal Text Editor' to learn more about them.
They will give you the ability to create files, name files, save files, and edit existing files.