Take your first step into the world of coding with command-line interface.

Warning: this tutorial assumes you are working on a Mac. If your are using a PC please follow the link at the bottom for a handy set-up guide.
So what even is a command-line interface?
A command-line interface is a way for you to give commands to your computer. It is an alternative to the graphic interface that you are likely using right now. But instead of dragging and clicking with the mouse to make things happen, in command-line you use your keyboard. You can create and delete files, install programs and use advanced search functions all without a single click.

And why would I use a command-line interface?
If you are a fast typer, and if you’re not not I would encourage you to practice, it can be much faster to complete tasks using a command-line interface than using a graphical interface like Finder. You can, for example install an application can with a single line of commands, no browsing, clicking and unpacking required. You could even set specific options for the installation all on the same line.
Also, it will make you look like a real life hacker and who doesn’t want that?
OK, fine. Let’s give it a go.
To try it out, open up your Macs built in command-line app Terminal:
- press command + spacebar, type terminal and press return (enter).
You should now be seeing an almost empty window at the top of which it reads: yourName-MacBook-Pro: ~ name$, follow by a grey block. This is your computer awaiting your command. From now on, all text that looks like this are commands you can type in your Terminal.
Cool! So what can I make it do?

You can move around your folders and have a look inside.
A new terminal window will open with your home folder as your working directory. From here you navigate your whole computer. Try typing ls and press enter. This will show you all the files and folders available in the directory that you’re in now. Want some more information, like file size, owner, type? Try ls -l . Pick one that has a d all the way on the left (indicating its a directory, or folder) and change into it by typing cd, a space, and the directory name. To go back a step, simply type cd .. . See if you can find your latest downloads, your favourite pictures or your best slideshows this way.
Got a little lost? Show the path to the directory you’re current in by entering pwd (path to working directory) or enter cd ~ to return to your home directory.
You can create new files and directories.
So you now know how to get around. But that’s just the beginning. Try changing into your desktop directory and typing touch file.text. Boom! You’ve just given live to a new file. You can even create a new file in a different directory than you’re currently in. Get to your home directory (cd ~ remember?) and type touch ./Desktop/new_file.txt. This will create a new text file straight in your desktop directory. The ./ here indicates the current working directory.
Too many files cluttering up your desktop now? No worries, just get to your desktop directory and make a folder for them by typing mkdir textfiles. You can move the files into the folder with mv file.txt ./textfiles/file.text, with the first argument being the original file name and the second being it’s new one. You can also use this to rename files and folders using this command. Try mv new_file.txt newer_file.txt.
Still not clean enough? Get rid of the files entirely with rm. Because it is assumed than anyone who knows enough to use a command-line interface knows what they’re doing this will not move them to the trash can, but remove them fro your computer directly. Now try deleting your textfiles folder. Not working? Directories have their own special command for removal: rmdir. Still not working? Try rm -r. A letter after a - is called a flag and r in this case stands for recursive, meaning it will go through everything inside the directory and delete it all. If you’re trying to remove a directory that has directories inside of it Terminal will prompt you for each one. You can override this by using rm -rf. Be careful with this as it is easy to accidentally delete important files this way.
You can add text (or code) to files.

But, you ask, what’s the point of having files if there’s nothing in them? Alright, let’s make some files with actual content. Try typing echo "Hello" >> greeting.txt. Now have a look at the files in your folder (ls, remember?) and you’ll see your new text file there. You can add more text like this echo ", world!" > greeting.txt. Again, be careful here. A single > will add the given string to the end of the file. A double >> will replace all of the file’s content with it.
Time to see the fruits of our hard labour. Type cat greeting.txt to show it’s contents on the screen. cat is short for concatenate, meaning to string together and as that name suggests you can use it to string the output of multiple files together. Let’s try it out: type echo "-- Greeting --" >> start.txt and then cat start.txt greeting.txt and you should see the content of both files on screen.
Bonus: you can also use echo to your terminal like an old well. If you enter only echo "Hello" without assigning a target file, the terminal will simply echo your words back at you.
You can search for files and search within them.
So what happens when we lose track of all these files we’ve created and what is in them? We search of course. From your desktop directory try find . -name “start.txt" and see what happens. The . in this case stands for the current directory. You can replace it with any directory you want. find searches recursively so find / will search through all the files on your computer. This may all seem a little useless right now but it becomes very powerful once you learn more command-line magic, like piping commands.
Last but certainly not least we can also search straight for content. If you type grep "Hello" greeting.txt the terminal will show you all the lines in which the word Hello is found. Go ahead and give it a try on a larger text file.
And so much more.
Congratulations! You’re now one step closer to being a real coder. But this is just a small foray in the world of Command-line. Are you eager to take some more steps? Maybe even a leap? Try out this free tutorial by Michael Hartl.
