As a developer I frequently use the OS X app called Terminal as my Command-Line Interface (“CLI”). What if you are not a developer but are still curious as to what the command-line has to offer? This article is a brief introduction on what the command line can do for using only a few simple commands. I am going to assume you are working on a Mac. If you are using Windows, you can open a Command Prompt (Window’s CLI) using some of these suggested techniques. If you are using Linux, you are far superior to us mortals and I will not insult your intelligence.
The Command-Line or CLI is a powerful and quick way to give commands to your computational device. The term “commands” sounds very formal and unforgiving so simply think of “commands” as “instructions”. We already give instructions each and every time we use any piece of hardware with an interface, be it a phone or laptop. Clicking and moving little pictures (icons) is more intuitive and easier to understand due to the visual analogues to the nature world (skeuomorphism). A Graphical Interface uses imagery as the primary mode of Interaction. In comparison, the CLI uses only text and can seem like an endless void poised to steal your lunch money and make you feel inferior in the process. I am obviously exaggerating, but rest assured the CLI is not only meant for those who are brave or “smart” enough. You can start using it today! Lets start with some simple examples:
Where Am I?
Open the Terminal app. Not sure how? Click the magnifying glass in the top right corner of your screen and start typing “Terminal”. If all goes well, the Terminal app will be the first suggestion to appear in the list and now you can click or press enter to launch the app. My Terminal looks like uses the Homebrew theme because I set the theme using apps preferences. The colour scheme provided by a theme is critical and is only a person preference. You are going good so far.
After the Terminal app has been launch, you will see a blinking cursor… okay … ready? Type pwd and press enter. You should see some text appear below where you entered the ‘pwd’ command.
The text you see will be different from my example because you are using a different computer, but what we did was instruct the computer to tell use our present working directory. If you do not like the sound of “directory” then mentally swap it would with the word “folder”. This command is useful if you are looking for a file or folder, get lost and need to figure out where you are. Sort of neat right?
Driving frequently required lane changes. Driving your computer using the CLI frequently requires the driver to change directories. Starting were we left off, type cd Desktop and press enter. We have now successfully changed lanes to the Desktop directory. Type cd .. , press enter and we are now back at where we started.
Lists Are Lovely
Command: ls, ls -l, ls -a
In our previous example I knew (and hoped) that there was a Desktop folder present and that we could navigate to it using cd Desktop because it is standard on all Mac systems. There will be moments when you will have no idea what and where you can navigate to. This means you will need to “probe” and see what is out there. Simply type ls, press enter and a list of the various files and folders within your current folder. Like a map, the a list provides with directions for where you can go.
Formatting can be applied to the list using the -l flag after the ls like so: ls -l. Add a -a to display all the hidden files, ls -la. Hidden files have a . (dot) prefix. A word of caution: hidden files are hidden for a reason so do not edit or move any of these files unless you know what you are doing.
Create And Annihilate
Type touch marketing.txt and press enter to create a plain text file named “marketing”. Type rm marketing.txt to remove the file. Again, be very careful what you remove files using the CLI.
If you navigate to a specific folder or file you may want to see where it exists with a more familiar interface such as the Finder app. No problem! Simply navigate to where you need using the cd command and then type open ., where the “.” indicates the current folder; open . translates to, “please open the current folder in the Finder app”.
One more thing… Downloading
Oh yeah, who needs a web browser when you can download a file using the CLI! Type curl -O, a URL of your choosing and press enter. Learn more about the super-duper fun curl command.
More to come
This article is a quick introduction to what you can do with the CLI and is in no way an extensive listing of all the super powers (and responsibility) that you can tap into. There is more to come!