An Intro To Command Line On A Mac
Overview
A straight-forward introduction for anyone who wants to understand how to get started on the command-line. Why should anyone care about this? Because if you’re into getting into web development, the command line is first step in exploring what can really be done with a web server.
Below is a small smattering of command line commands to get you started. They assume you’re working on a Mac (hence the post title) where the Terminal program comes pre-installed.
Sample Command Line Commands
Open the Terminal program on your computer and type:
pwd
and then hit RETURN to display the contents of your home directory (or folder).
To create a new text file named banana.txt, type:
nano banana.txt
RETURN to create and open a new text file in your home directory with the nano text editor.
Now you can just start typing something like:
Bananas are tasty.
to start entering content. To save your new text file, hold down the control key and hit the ‘O’ key CONTROL-O, then RETURN and finally CONTROL-X to exit out of the nano program.
To see your new text file in your home directory, type:
ls
RETURN and you should see it in the list of files.
To make a new directory named food, type:
mkdir food
RETURN and if you enter the ls command again you should see the new food folder there in the list of folders and files.
To move the banana.txt file into the new food directory you just created, type:
mv banana.txt food/
RETURN
Then to go into the food directory, (or change directory) type:
cd food
RETURN – then type the ls command again to see what’s in there – which should only be your banana.txt file.
To delete the banana.txt file, type:
rm banana.txt
RETURN which will remove (instantly delete) the banana.txt file.
To back out of the now empty food directory, up one level and back into your home directory, type:
cd ../
RETURN and then type the ls command again to see the contents of your home directory.
To delete the food directory, type:
rm -r food
RETURN and you’re back to where you started from.
Once you get the hang of working in the command line on your local computer, you can start thinking about securely connecting to a remote computer – such as a web server – via SSH, or Secure Shell.
The first step in that process is to generate an SSH key pair.