You are currently offline, so some features of this site may not work fully.

Your browser doesn’t support some of the latest CSS features used to build this site.

Read more about my usage of new CSS features.

This article is part of a new series I’ll write entitled Ain’t Scary, where I intend to write little tips to get you going on things that I’ve started working with.
Note: I primarily use a Mac so this is going to be geared towards hipsters Mac users.

Navigating your environment

I barely ever use Finder on my Mac anymore as navigating your directory structure on your machine is super easy with the command line (even easier with shortcuts - more on that later).

Remember these

Change directory:

cd

Change directory to your machine's root, for example:

cd ~

Back up one directory:

cd ..

List contents in a directory:

ls

List contents in a directory, with full detail:

ls -la

Creating files

Creating files and directories is easy too - I often create a bunch via the command line before starting a project.

Use these

Create a directory (and head into it):

mkdir yourProject && cd yourProject
Note: Performing commands one after another with && makes things a little quicker too.

Create a file:

touch .gitignore

Write to a file (also creates files if it doesn't exist):

echo "Hello, World!" > index.html

Open a file:

open _yourProject.sublime-project

Open the directory you’re in:

open .

History

Searching your previous commands can be useful if your workflow involves a lot of repetition.

Try these

If you want to repeat a command you know you did a little while ago:

history

List a specific number of commands:

history 5

To search your history:

history | grep git

Where git is your search term.

When your command history comes back they'll all have indexes beside them, so to run one of the commands in the list use:

!12

To run number 12 in the list for example.

Sudo

You may know sudo for overriding privileges, running as an admin when you execute commands, but this pretty handy tip is to hit:

sudo !!

When you've tried to do something that fails without the correct privileges.

This simply repeats the previous command with superuser privileges.

Bonus round!

Your challenge:

  1. Don't use Finder for a day
  2. Create some shortcuts in your .bash_profile for your most frequently used navigational commands
  3. See how much quicker it is!
  4. Then comment below and let me know how you got on!

TL;DR

There’s not too much here yet but I’ll be adding to Command Line Ain’t Scary as I go, as well as writing more Ain’t Scary posts introducing front end technologies to beginners.