Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this chapter we are going to be taking a look at some Unix commands and programs and seeing lots of useful things that we can do. I want to start out by just talking about some of the basics of commands and this is really a follow-up to the discussion we had back in Chapter 1, where we saw the basic structure of a command. Remember it was command, then the options, then the arguments. I want to go a little bit deeper here and take a closer look at commands. Let's start out with just the simplest command that we've seen so far, echo. So echo 'Hello World,' just echoes back that string to us, right. That's a classic command. Now a command is actually a program.
It's not a big program like Photoshop or Excel, but it is still a program. We typically just call it a command. The other thing you need to know is that commands are not somehow magic. They're just files that you are executing. That's all they are. They are files that are executable and when we execute them, they do the business of the command. You remember when we talked about where files are located in the Unix file system, I told you that /bin is a place where we store a lot of these files and that's where echo is. So /bin/echo is where the file is located, and all we are doing is executing it, and to execute a file, you just type the file name. That's it.
That's all there is to executing a file and then we'll pass in the argument, 'Hello World'. So when we type echo, it's just a shortcut for saying go to /bin/echo and run that file with these arguments, and so commands are essentially a shorthand for going to these files and executing them. We'll talk a bit more about how it knows where to find these in the next movie. For now, let's look at whereas. whereis will tell you where that file is located, or you can use which, which will also tell you where it's located.
We can also use whatis to tell us the simple information about the command. If we do it for echo, we'll get a lot of page of information as it tries to find everything that references echo. I am going to instead show you with banner, just so you can see a nice simple one line listing. So the banner tells us, ah, what it does? It prints a large banner on a printer. There are few other helpful things to know about working with commands. First is that it's very common that you can pass in the -v, the --version or --help options to a command to find out more. A lot of times it will just have the command itself followed by the option.
Now that's not always true. A lot of commands don't respond to these. But if you're trying to figure out how to work a program,and man pages don't have anything, you might try help. If you are trying to figure out what version of Ruby you have installed, or you might try passing in the --v or --version. So those are just common idioms that are frequently implemented. If you want to exit out of a program and you can't figure out how to do it, Typically Q, X, Ctrl+Q, Ctrl+X or the Escape key will get you out of it. We saw a Q when we were looking at the man pages. Remember man pages use less. That's the command that it's using to display those pages, and Q exits out of that.
When we were working in nano, we saw how Ctrl+X is what gets us out of nano. I would say probably Q is the most frequently used. Escape is probably the least frequently used, but you might try all of those. If can't figure how to get out of a program. If you're really stuck then you can force quit and you can do that with Ctrl+C. That's the Unix way to completely cancel the process that we're working on. So Ctrl+C will just tell Unix, hey, stop what you're doing. You also can close the window, the Terminal window on a Mac. But be advised that if you do that, the process may keep running. You haven't told Unix to quit it.
You've just said, hey, I want to abandon whatever I'm doing. The process will keep running. When it finishes, it will just stop at that point. But it doesn't actually stop the process itself. Ctrl+C is what does that. So be advised about that difference. The other thing you should know is that you can put semicolons between commands. So we can execute one command, semicolon, followed immediately by another command. That can be really useful if we are trying to do two things really fast. Let's say we want to move a log file to a different name and then we want to create an empty log file back in its place.
So in one command we can essentially do both really fast, within a matter of milliseconds, and as I already mentioned we have whereis, which, and whatis available to us to find out more information about these commands. I told you that Unix knows to go look in that bin directory in order to find the echo command. In the next movie I want to talk about how it goes about doing that.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.