In this lesson you'll learn how to use the CLI (Command Line Interface) to read, create, and remove files and directories on your computer.
By the end of this lesson, you'll be able to:
Now that we’re up and running, let’s type some commands, shall we? In a terminal window, we type “hello?” and press enter. Terminal responds with: “-bash: hello?: command not found”. Translation: “I’m not following you.” Now, if we type “Where am I?” into the terminal (“$ Where am I?”), again we get a similar response: “-bash: Where: command not found”. OK, then. We’ve established that our command line doesn’t understand plain English. We’ll have to use special words to write our commands. Remember, we’ve left the GUI world behind. We no longer have pretty warning messages and alert boxes. But not to worry! In due time, these cryptic command line messages will be as clear as any warning box you’ll ever see.
pwd
ls
cd
We’ve learned a lot of command line… commands. Let’s compare what happens in the GUI (Finder on Mac) when we use some of the most common commands in Terminal. To illustrate this, we’ve set up our Finder and Terminal side by side. If you’re a PC user, it might look a little different, but the results will be the same! Let’s cd into the Documents folder. The terminal returns “macBook-Pro-(8): documents EmilyLogan$”, which means, “Hey, you’ve moved into the Documents folder as the user EmilyLogan.” This will say your username, not mine. If we wanted to achieve the same thing in the Finder, we’d just click on the Documents folder. In the GUI, you can see what files and folders exist in the Documents directory — the zoom folder. To do this in Terminal, we use the ls command. Next, let’s make a folder called “myfolder”. Oh wow, look what happened in Finder! “myfolder” was created in the Documents folder. We’ll cd into “myfolder” in Terminal, which, again, is the same thing as double-clicking into “myfolder” in the Finder. Now, let’s make some files. In Terminal, we type “touch”, “index.html”, and “style.css”. Instantaneously, we see our two new files appear in Finder. To see these files in Terminal, we’ll use the list command again, which returns the names of the files we just created. We can remove the “style.css” by using the `rm` command and see that it was in fact deleted by using the list command. Now, we can move out of “myfolder” and back into Documents with “cd ..”. This equates to clicking the back arrow to take us back to the folder we were just in: Documents. Terminal tells us where we are by returning “macBook-Pro-(8): documents EmilyLogan$”.