Created by Christopher Lawrence GS '24
The command line or Terminal is a free, application that ships with Mac OS and and Linux operating systems distributions. It can be used to interact with your computer in a way totally different from pointing and clicking. In this tutorial, we are going to use the Terminal this application to: navigate throughout our computer's cyber space, play games, and get silly. As we go, we are going to learn about some of the etymology behind the commands we give, and learn how the actions we make through the GUI (Graphical User Interface) pointing and clicking translate to single sentence commands.
Commands and Interactions
Throughout this tutorial when you see a command appear, type or copy and paste the words into your terminal. It feels like cheating but its a good way to start.
[It feels like cheating but its a good way to start]
Opening the Terminal
To get started, find the Terminal application on your machine. The icon should look something like this.
For MacOS users, open finder or applications and type "Terminal" into the search bar, and hit enter
If you are on a Linux machine, click the show applications app (shown below) and search terminal. Once you have found the application, click to open it.
If you are on a Linux machine, click the show applications app (shown below) and search terminal. Alternatively, you can use Ctrl + Alt + T to open the terminal directly. Once you have found the application, click to open it.
You should now be met with something similar to this. Make sure not to stare too deeply into the void, for the void stares back.The words we type into the terminal have power, they are commands that we (the user) are giving the computer. And in fact, not only does it stare, it also speaks. Lets learn our first command.
echo and pwd
Type the following command into the terminal and hit enter.
*Gasp* the computer is listening, it repeats the words or phrase we give it, thus echoing our commands. The line that appears after we run the command, is the output.
The computer also knows where we metaphorically live, in our computer cyberspace
The output should be something similar to this
This command is telling us where our "Home" directory is
The $HOME directory belongs to you, the user. It functions to separate your data from the system-wide data, to avoid file redundancy, and to make the preservation and backups of important files relatively simple.
We can easily have our computer repeat our current location back to us by using
pwd seen above
This should return the same output. (See above)
pwd stands for print working directory or in plain speak, show me where I am within my computers cyber space. When we create files, or write scripts in the terminal, the files will be output to this directory.
But what all is within this directory?
To find out what is within our directory we can use
ls stands for list and can be used to list the files (white pdf's that I need to read) which we can interact with, and folders (blue) to whom we can travel.
To create some files within our directory we can use the Touch command.
Touch is a standard command used in UNIX/Linux operating system which is used to create a file or multiple files.
We have brought a file into this world! (evil laughter). If we run ls, we should see our new creation, highlighted above.
We can even create multiple files at once.
Try this command on your own. Remember to ls, afterwards to view the file locations.
touch filea.txt fileb.txt filec.txt
Touch is very good and effective at its job which is why many linux/unix contributors use it in their scripts to create empty files to which they pass values. Touch is a good catchall and proof of concept command.
If at anytime you are uncomfortable running a command or have forgotten what exactly it does you can get help by typing man and then the command. In Linux the "man" command is used to display the user manual of any command that we can run on the terminal. It provides a detailed view of the command which includes optional flags (-n/-h/-e etc) that we can use to achieve our desired output. Lets try it out.
The above command opens a window within our terminal window and displays a host of information about the ls and echo commands. To escape from this window we simply type
q when finished.
This completes part 1.
In the next tutorial we will learn how to read, write, and tell the difference between two files! See you there.