Join Scott Simpson for an in-depth discussion in this video System basics: The command line, part of Linux Tips Weekly.
- [Instructor] One of the primary ways of interacting with a Linux machine is through the command line. Instead of using a graphical interface with windows, links, and buttons, we can communicate with the system through typed commands and read information through text respsonses that the system gives us. This text interface is called the command line and we use that mode of communication through software called the shell. A shell provides a place where we can type commands and depending on the shell, it can have other helpful features aside from just accepting commands. The commands we use are generally in the pattern command, options, arguments.
The command portion is the name of a program or a tool that we want to use in order to accomplish something. If we wanted to send a network message to a computer to see if it was responding, we'd use ping. To see what files and folders there are in a certain path, we'd use ls. And to edit text, we might use nano or vim. Some commands work without any options or arguments but usually we'll use an option to tell the command what to do. We might tell ping to stop after five pings or tell ls that we want to see the files in a wide listing. These options modify how the command works by default.
The arguments are how we tell the command what to work on. Usually, the arguments to a command are names of files or folders. But they can also be IP addresses or host names or strings of text. In our ping command, the address of the remote machine we want to ping is the argument. In the ls example, it would be the path to a folder whose contents we want to see. And with the text editor, it would be the name of the file to edit. The place where we use these commands is called the prompt. It's usually a line of text that gives us a little bit of information. We can get to this through a terminal application.
Often, the prompt will show the user and the host name and the path of the current working directory. It usually ends with a character like a greater than sign or colon. Or in the case here on ubuntu, a dollar sign for regular users, and a pound sign for the root user. I say usually because this prompt can be changed to show different information or to show nothing at all. We'll take a look at how to customize that later in the series. For now, though, whatever your prompt looks like, this is where we'll type commands. It's important to type commands properly. There's no spell check or way for the system to know what you meant to type.
This can one of the most frustrating things about learning to use the command line. What you type needs to be correct. If it's just off by one letter, you'll get an error. Seeing an error from the shell isn't necessarily bad or dangerous or a sign that you've broken something. It just means the shell can't figure out what you mean. I'll type a command here. The ls command to list the files and folders in a given path and the root of the file system. And I can see that response here. Now, I'll mistype the same command so we can see an error. And the shell tells me that the file isn't found.
There's no program called lls that the shell knows how to find. If I mistype it differently, with a slash going the other way, I get a different response. This greater than symbol here means that the shell is waiting for an input and what I type here will get passed to the command. The backslash character here is used for line continuation and for escaping as we'll see later on. As opposed to the slash, which represents the root, and acts as dividers between folders in a path. So if I type a regular slash here and press enter, I'll see the listing of root, just as if I had typed the command correctly in the fist place.
And if I write out a command and decide not to run it after all, I can use CTRL+C to cancel it. There's really no way to get accustomed to the command line other than by using it. But where do we find the commands? As you explore, you'll find commands to run and if you need to find a command that does something in particular, you can use the apropos command and some text like copy. To see commands with descriptions that include the text copy, take a look at the list then see if any of the commands look like what you're trying to do. I'll scroll up here and this one, cp, says that it copies files and directories.
That sounds useful. To find out more about a command, we can use the man command to search the built in documentation called the man pages or manual pages. For more information, I'll write man cp. This is the man page for cp and it shows the command and lists options and arguments that can be used with it. Option in square brackets here corresponds to where the options go in the command. And the options are listed down here, in this case, in the description section. And then the arguments are shown afterward.
In this case, we can see that there are three modes for using cp, two of which correspond to using the dash t or dash capital t option and one here in the middle that doesn't. In a description like this, the dots indicate that more than one option or more than one argument can be used. We can see that cp takes two or more arguments. The last one is the destination, where files are copied to. And the first, or really, any arguments that come before, the very last one, are sources to copy from. These could be files or directories.
The man pages are a very valuable resource, both as you learn to use the command line, and even as a veteran of the command line, because it's impractical to memorize all of the commands and options available. You'll start to commit a few of them to memory as you use them frequently but don't try to cram all of them into your brain. That's just a waste of time. Almost every Linux installation has the man pages installed so it would be a rare time when you are without some kind of support of the command line. I'll press q to exit the man pages and I'm back at the prompt. As you use it more, you'll see how powerful and flexible the command line can be for all kinds of tasks.
Note: Because this is an ongoing series, there is no certificate of completion available for this course.