Command line basics for frontend devs

Ah, the good old terminal. You know, the intimidating black hole with neon green text that every hacker loves.

Yes, it might be intimidating at first glance, and you can do some pretty scary things with it (sorry, I don’t have any concrete examples), but all in all it’s a powerful tool for running scripts, creating files and folders, making things happen.

In this lightning article we will touch some of the most basic commands you need as a frontend dev using the macOS’s terminal, contributing to some of that goodygoody productivity.

Let’s get our hands dirty

To get at grasp of these commands, we will create a folder, enter that folder, create a file, add some content to that file, and print the content in our terminal.

Sounds fun, right?

So, let’s run some commands!

Note: You might be thinking; “Run? Isn´t that somehting you do outdoors, like, at a track or something?“. Yes, running is something you do with your feet, and body, and you get sweaty and tierd (it´s a real healthy thing, we all should do more of it!). But, in this case, each time I say run, I refer to writing a command and pressing enter. So if I say run ls, or run the command cd SomeFolder, I actullay mean “type cd SomeFolder inside your terminal window and press enter“.

Got it? Gooood.

Alright! Let’s get started!

Open a new teminal window on your mac. Press cmd + space, type term and press enter.

Great. By default our terminal opens a window in our home or user folder. In my case it’s called hansmaast or ~. Yup, ~. Take note of that. That’s your home.

To list what we have inside our ~ folder, run ls, I personally think of it as a short name for list directory.

You should now see a list of names. Like Documents, Movies and Downloads.

Next, we will make a new directory (or folder if you like) inside our ~ (home).

Run the command mkdir TuffyTerminal. The run ls once again. Can you see your TuffyTerminal in the list?

Notice something else here. All the directory names inside home (~), starts with an upper case. I personally like to follow that convetion, but that’s up to you to figure out how you like it.

So, we should now have a TuffyTerminal directory in our home (~). Let’s get into it.

To checkout our directory, we can run the cd command. I´ll show you a little trick here.

type cd and press space. Then press tab like 4-5 times and notice what happens.

Do you see it? Pressing tab cycles through our directories.

Press tab until you get the name TuffyTerminal, then press enter.

Notice that our ~ (home), now has changed to ~/TuffyTerminal. Amazing.

Now, inside the ~/TuffyTerminal, run the command ls.

It’s blank! Why? Because there’s no files or folders inside it. Let’s do somthing about that.

To create a file, we’re goining to use the touch command.

Run touch makeTheTerminalGreatAgain.txt, then run ls.

You should see our file.

Run echo "This is a important note!" >> makeTheTerminalGreatAgain.txt.

Then run cat makeTheTerminalGreatAgain.txt.

See some text? Nice!

Note: Try pressing tab after the different commands. It will save you some time by not having to type the whole file / folder name.

So, we have now created a folder (mkdir), entered that folder (cd), created a file (touch), added some text to that file (echo) and printed it’s content in the terminal (cat).

Let’s do a bit of a cleanig up.

To navigate back to our home (~) folder, run cd .., or cd ~.

Then we will remove our folder by running rm TuffyTerminal.

You should get an error saying rm: TuffyTerminal: is a directory.

No worries, to delete a directory we’ll simply add -rf, to the command.

Run the command rm -rf TuffyTerminal.

Then run ls again.

Our folder and it’s content should now be gone! Forever!

Check out my post on gritty git basics you need to know if you would like to enter the next level of commandline neccesities.