You’ve probably experienced a time you’ve had a developer just sigh and take your computer from you instead of watching you entering in code to a scary looking terminal window. Wouldn’t you rather know a little bit of what they’re up to? Wouldn’t you rather figure out the basic commands of knowing how to use git (which you’ll inevitably have to use at some point)?
These are the very basics, but they’ll certainly help with getting you familiar with using terminal and not feeling as scared about deleting everything on your computer.
First off, you can start using the command line by opening up the Terminal app. The easiest way to do this is to search Spotlight (shortcut: cmd + space) for Terminal.
Stands for change directory (or folder). You can use this command to navigate into a folder.
Similarly, you can navigate up, or out of a folder by adding ../ to the beginning:
Stands for list. Lists out the contents of a folder or directory. If I want to see the contents of my Dev folder, I'd type:
…and then press enter. If your folder were named Development instead, you'd use the next command to save you a little time.
Completes arguments. If you’re drilling down into a directory, use tab to finish the folder name so you don’t have to memorize it (or worry about spelling it wrong).
This will let you navigate through previous commands you’ve already entered. I’ve found it’s especially helpful when using git add and push or when you need to remember that command that dev told you to use and you haven’t cleared your window.
Stands for make directory. Enter in:
To create a new folder within the directory you’re in.
Removes. You can use this to, say, remove the directory you just created. (Hint: use tab to complete the directory name.) This command also removes files, but be careful because they do not go to the trash can. Instead, they’re deleted immediately.
Created a stylesheet, but it’s in the wrong folder? Use the mv command to move the file to the correct folder.
mv style.css /stylesheets
Clears the current window. Have your terminal window cluttered up with stuff and just want to not be distracted? Enter the clear command to start fresh.
If you’ve ever tried to do a git commit and forgot to add a message, it’ll switch views to something that you might have trouble getting out of. This is git opening up vim for you to edit something. All you need to do to exit is:
This means write (or save) and quite. (Yes you need the colon.) Press enter and it should go back to the view that’s more familiar. If that doesn’t work, try adding an exclamation point to the end.
Extra points if you actually type a commit message before quitting!
This’ll let you view websites you’re building or testing locally. First, cd into the directory or folder you want and then enter this command:
python -m SimpleHTTPServer
If you’re having trouble with the port number already being in use, add a different number onto the end of the statement. Ex:
python -m SimpleHTTPServer 8080
Intimidated when people say you should learn something like Vim, but don’t know where to start? You can enter vimtutor as a command and start learning immediately.
That’s right. Terminal comes with a built in way to learn how to use it’s code editor, so no excuses.
Interested in learning more about how to use the command line? Check out The Art of Command Line.