Writing with the command line
iterm. You can keep it on your dock with a right click on the icon once it's open if you want to have it only a click a way – but using
space and typing it is a good way to get use to using your keyboard more.
Speaking of, once you open iterm – I'm just going to call it the terminal from here on out – you can use the arrow keys to move your cursor left or right – or move through the history of your commands by going up and down. You can use
Option and the left and right keys to jump word by word.
cd ~/Desktop touch index.html
This moves to your Desktop. Then creates a blank file called
HelloWorld.html. Now you can add some text to it.
echo "HelloWorld" echo "HelloWorld" > index.html echo "HelloWorld" >> index.html cat index.html
echo prints whatever you tell it. The
> takes that output and overwrites whatever you tell it. The
>> takes the output and appends it to the target.
cat prints out a file for you.
Now let's try using
That's not an effective way to write a lot of text – or code. Most systems come with a basic text editor called
nano. Most coders will eventually shift to
emacs but you can depend on nano being there and it's pretty straight forward to use. It's simplicity is helpful.
So let's try using it.
Try to delete the extra Hello World line. Now you are using nano... press
x to quit and you will be asked if you want to save the changes from this 'buffer' – press
y for yes and then
enter to keep the same file name.
and running a server
Now we are going to use
python to run a server and view the file. This should work with
python version 2.whatever which should be on your mac.
python --version python -m SimpleHTTPServer 8000
Now go to your browser of choice and go to
http://localhost:8000 and you should see HelloWorld.
c to stop the server.