Introduction to Terminal

Before the beautiful interfaces given to us by Windows and Macintosh, users interacted with their computers via the terminal window.  Shell, command prompt, terminal window, all of these terms are just names for a program your computer runs that allows a typed input and renders its output exclusively in text.  Terminal windows are the most basic way to access and manipulate files stored on your computer.  While today’s GUIs (guided user interfaces) are much prettier and more intuitive than using the terminal, oftentimes using a terminal window is the quickest way to get something done.  In this post, we will introduce you to the Git terminal, which we will make use of in future blog posts!

Background and Basic Set Up!

The first terminal program was developed by the folks at Bell Labs and was built for the Unix operating system. The Unix operating system is the predecessor of the Linux operating system, and believe it or not what the Mac OS genealogy is based on as well. Why this is important is because this means that navigating a Mac terminal and a Unix/Linux terminal are pretty much the same thing. Windows operating systems are not built upon Unix, meaning that a Mac/Linux terminal does not accept the same commands like a Windows terminal, although there are similarities. In light of these differences, we are going to teach you how to use a Git terminal which is the same on both Mac and Windows.

If you have a Mac, you are all set because Git is preinstalled on all Macs so all you have to do is open your terminal and start following along! If you are a Windows user, you can go to the Git homepage and download the Git package, which will be saved on your computer as a program called Git Bash. Don’t bother downloading the source code; just download Git for Windows. We recommend using the default setup options for Git as this will keep Git from integrating too heavily into your Windows operating system.

Navigation via the Terminal

The first thing to understand about the terminal is navigation. As soon as you open a terminal window, you are within a folder (the old school term for a folder is a directory). The command that returns your current folder location is:

pwd      //this stands for ‘print working directory’

This command should spit out a file path. That path is your current location. To navigate back one directory, simply input into your terminal:

cd ..   //this changes your directory to one level up

Now, using pwd shows you where you are currently located. To see the which files are located within your current location, simply type:

ls      //this stands for ‘list screen’

Now you can view all of the files and folders that you might want to explore/edit! If you want to navigate into a folder that you saw when you typed ls, just type:

cd *folder name*     //this navigates into the folder specified

Using these three commands, you should be able to navigate in and out of all file systems in your computer. Use ‘cd’ to go up and down directory levels, ‘pwd’ to see your current location, and ‘ls’ to see all of the contents within your current location. This is how we used to navigate computers before we had pretty icons and displays; truly the old fashioned way!

Creating Folders and Files!

Using the terminal to make new folders and files is a breeze. Type along with the instructions to create your first folder via the terminal and populate it with a few new files! In your terminal, navigate to your desktop and type:

mkdir terminal_stuff //mkdir stands for ‘make directory’

The mkdir command allows you to make a new folder and title as whatever you type afterward. Minimize your window and look at your desktop; you should have a new folder there called terminal_stuff. Pretty sweet, huh? Now, let’s put some files into your new folder. Navigate your terminal into terminal_stuff and type:

touch index.html

The touch command is a very versatile command. If there is not a file by the name of the one you enter after typing the command, your computer will create that file. If there is a file by the specific name, the computer will update the timestamps of that particular file, which is helpful for keeping track of modifications.

Renaming and Moving Files and Folders!

Renaming items and moving them from one location to another are done with the same command in the world of UNIX-based terminals. The command is the following:

mv *target* *destination* //this command accepts two inputs

The target input is the file or folder you wish to relocate or rename. The destination input is the folder or path you would like to relocate the target into. If the destination input is not the name of a folder, the computer will assume you wish to rename the target input. Let’s try this! In your terminal, from the DESKTOP directory, type the following:

mv terminal_stuff TERMINAL_STUFF

Now, when you type ls, you should see that the folder terminal_stuff has been renamed appropriately. Fun stuff, huh?

Deleting Files and Folders

If you wish to remove an empty directory via the terminal, you can simply run:

rmdir *directory name*     //stands for ‘remove directory’

This will remove an empty directory quite readily. If you wish to remove a particular file from within a directory, from inside the relevant directory type:

rm *file_name*       //stands for ‘remove’

If you wish to remove a directory along with the files inside of it, you must use what is called an optionOptions for terminal commands are preceded by a – (a dash) and their purpose is to slightly modify or enhance a way a particular command is executed. To delete a folder and its contents, run the following:

rm -r  *directory_name*

The -r option is called the recursive option and it allows the rm command to remove all of the files within a directory and delete the directory as well.