When I say ‘computer’, most people think of this:
However, when I say ‘computer’ to a computer expert, they think about this:
Vastly different right? Every computer expert a least has the basic knowledge of command line usage. The reason for this is that the command line is the most basic, raw, and primal way of interfacing with a computer, that allows for more complete control and higher productivity. To run firefox in a command line, you type:
As opposed for looking for an icon or searching a large list of programs (i’m looking at you windows 8!). This simplicity and powerful nature of the command line leads to huge increases in productivity. By the way, these blocks indicate snippets of command line ‘code’, which do not include the stuff before the ‘$’. So in this case, you would type ‘firefox’ into your shell.
Because of the major inconsistencies between the original (unix) and the skewed (windows) command lines, I will be talking the unix shell, which is ‘bash’ by default on most Linux, and osX machines. (Once using both enough, you will see why). Bash is a free and opensource derivative of the original command line interface, the shell (or sh). Bash stands for ‘bourne-again shell’, which is extremely appropriate, given its history. This article will cover most of the basics of using a shell.
To start your shell, just open up a ‘terminal’ program on your computer. If you are running windows, you need to install cygwin to get this functionality.
When you start a shell, you are ‘placed’ in a directory on your computer. Think about opening a file explorer in windows, or finder on a mac, you are pointed at a location on your computer, like my documents or my programs (in windows). To find out where you are on your computer, type ‘pwd’:
onionchesse@hunger:~$ pwd /home/onionchesse
That output, the ‘/home/onionchesse’ is the current directory, or where I currently ‘am’. I can find out what files are in this location by using the ‘ls’ command:
onionchesse@hunger:~$ ls bin Copy Desktop Documents Downloads Dropbox Minecraft Music Pictures Public Templates Videos
Hey, there are all my folders which are inside that ‘current directory’. Lets now try moving around! To move around, we use the ‘cd’ or change directory command:
onionchesse@hunger:~$ cd Minecraft onionchesse@hunger:~/Minecraft$ ls MagicLauncher_1.2.5.jar Minecraft.jar Mods TechnicLauncher.jar
The cd command moved us into the Minecraft folder, and ls listed the contents of the Minecraft folder, which has some cool jar files! (Pro Tip: You can press tab when typing out a directory name to autocomplete it if the name is unabiguous! Ex: ‘cd Mine<tab>’ completes to ‘cd Minecraft/’). Typing out ‘cd ..’ will take you back ‘up’ a directory, and typing ‘cd ~’ will take you to where you started! (This is called the ‘home directory’ on unix machines, and it is represented by the ‘~’). These little shortcuts add up until you can save yourself a ton of keystrokes.
Lets now create a text file! The ‘touch’ command creates a text file:
onionchesse@hunger:~$ touch MinecraftIsAwsome.txt onionchesse@hunger:~$ ls MagicLauncher_1.2.5.jar MinecraftIsAwsome.txt Minecraft.jar Mods TechnicLauncher.jar
Hey! MinecraftIsAwsome.txt showed up! Lets see what inside it! The ‘cat’ or concatenate command will print out files (as text) to the command line:
onionchesse@hunger:~$ cat MinecraftIsAwsome.txt onionchesse@hunger:~$
Oh no! Nothing got printed out! This is because there was nothing in the text file to begin with… We need to fill that text file with information to print out. Next week, i’ll talk about i/o redirection, which will allow us to easily write to files from the command line! In the meantime, open up Notepad, Word, or Microsoft Paint and edit that file the way you’re used to. Just make sure to save as a text file!