I hate to break it to you but the scariest thing that you have heard about Linux is true: there is a window where you type in strange commands and mysterious options. It might surprise you to learn that Windows has the same type of window, called the DOS Command Prompt. If you got along fine in Windows all these years without using it then you can get along fine in Linux without using its command window either.
However, many power users of Windows often rely on the command window to do things more efficiently and quickly than they can by using a graphical utility program and some use it to do very specific actions which are difficult to accomplish any other way. So it is with Linux. The power of the command line is at your fingertips but it is up to you to use it or not.
Let's dive into it and you will see that it's not really so intimidating. Once you get the hang of it, you may decide it's kind of fun being a command-line Linux wiz.
I assume you have been following this series of articles and have installed Linux Mint. If you installed a different distro (version) of Linux, some of the menus, icons, and other features may vary; you can follow along on your own distro and the commands and syntax will work equally well.
In Linux Mint's main Menu, you will see an icon in the Favorites bar that looks like a computer monitor. It launches Terminal, the equivalent of Windows' Command Prompt. Terminal also has a launcher in the Accessories submenu and it may have a launcher in your taskbar panel as well. Go ahead and start Terminal.
You will see a fairly simple window. You can customize it in various ways in the Profile Preferences dialog box of the Edit menu but it really is a program for typing in commands rather than flashy GUI features.
Terminal does have a quirk that may throw you. It doesn't copy and paste the same way other Linux applications do. I don't know but I suspect it might be some kind of holdover from its early days; perhaps it's a Unix thing and they tried to keep it compatible for Unix users. Anyway, instead of Ctrl-C and Ctrl-V to copy and paste, you need to use the shift key as well: Shft-Ctrl-C and Shft -Ctrl-V.
However, Linux has a trick to sidestep that: you can copy text simply by highlighting it. You don't need to press any key at all. Selecting the text with your mouse and releasing the left button copies it into a buffer, an area of memory for temporary things. Then you can put your cursor somewhere, like Terminal, and press the middle button (usually a scroll wheel) and it will paste the text. So if you want to copy the commands we discuss on this page, highlight them and then middle-click them into Terminal.
Whenever you are working in Terminal, the computer will keep track of where you are working: a directory (folder) on your own computer or possibly another computer if you are logged into it over the internet or your office network. Because most commands affect files and folders, Terminal always knows where to apply those commands: if a command does not specify otherwise, the command is applied to your current, or active, directory.
When Terminal starts up this way, from its launcher icon, it makes your active directory your Home folder. You can see this by looking at the prompt, which is a bit different than Window's famous C:\> prompt. Terminal's prompt shows you your username and the computer you are currently working in, in the form of username@yourcomputer. So your prompt may look something like janedoe@janescomputer.
Remember above where I mentioned being logged into a network? If so, your prompt would show a different prompt, to let you know where you are: login_name@remote_computer. For example, let's say you log into your account on your webhosting service in another city. On your webhost's system, your user account is “admin_jane” so your Terminal prompt would read admin_jane@somewebserver. Just by glancing at your Terminal prompt, you know which computer system you are working with..and because you can have multiple Terminal windows open at the same time, that's extremely helpful so you don't get confused.
The next part of your prompt shows your current directory. When you launch Terminal from the menu, it automatically makes your Home folder the current directory. Home is indicated by a handy little shortcut, the tilde symbol, which looks like ~. If you have used the Windows command line, you know it's a lot of typing to get to your personal folder (My Documents): you type C:\Users\(yourusername)\Documents. Linux reduces that to a single symbol which you can use in any appropriate command. If you navigate to other parts of your system, using commands we will discuss shortly, the tilde will be replaced by the path to whatever your current directory is.
Finally, you will see a dollar sign. That's simply a marker to indicate the end of the prompt. Anything you type after the dollar sign is a Linux command.
So, to review, your Terminal prompt will look something like janedoe@janescomputer ~ $ and you type various commands, sometimes including options, file names, folder names, or other things, after that prompt, then press Enter to execute the command.
Let's try out our first command. We'll list the files in our current directory by typing ls (that's a lowercase L and S, not a numeric 1). Linux commands are case sensitive and, as far as I can remember, they are always in lowercase so just get used to typing mostly lowercase in Terminal (some options for commands are uppercase, however).
That should show you the main folders of your Home folder (Documents, Downloads, Pictures, etc.) and possibly some files if you have saved or copied any to your Home folder. You probably noticed that there are various colors used in the display. Terminal displays folders in one color, another for general files, other colors for specific file types (such as images), and more. That makes it easier to spot what you are looking for.
Most commands have some options available. Two options for the list files command are l and a (again, that is a lowercase L, not a numeric 1). The first one displays the file list in its long format, showing permissions, owner and group like we saw in the Compact View style of the file manager, Nemo. The second one shows us all of the files, including those that are hidden (i.e., the first character of the filename is a period).
We indicate to Terminal that we want to use one or more options by prefixing it with a space and a hyphen, as in ls -l or ls -a. We can also combine the options, to show all files in the long format, by typing ls -al or ls -la (the order does not matter). Try it out yourself in the Terminal window now, using the options alone and together.
Now let's use another command to get rid of the mess in our Terminal window. Type clear and press Enter and the display window will be cleared.
Terminal remembers what you have typed during your session, even if you close its window and launch it again. By pressing the up and down arrow keys, you can go back to previous commands that you typed, saving you time. Once you find the command that you want, you can add to it or edit it with the backspace and left or right arrow keys. Try scrolling back through the commands we typed and changing them, for example from ls -l to ls -al.
Now let's move around a bit. Just like in Windows, the command to go to another folder is cd (change directory). So, in your Home folder, the ls command shows you subfolders like Documents and Videos and we can change our current directory to one of them. Type cd documents and press Enter.
Oops, it says No such file or directory. Remember that Linux commands are case sensitive? That includes the objects or targets of the commands as well. So, to Linux, the folder named Documents is not the same as a folder named documents. The same is true with file names as well: myFile.txt is a different file than Myfile.TXT and both of those files can reside in the same folder without conflict.
Linux will help you if you're not sure where to go: Terminal has auto-suggestion abilities. If you type something and press Tab twice, Terminal will do its best to guess what you may want next. If you just typed a couple of letters at the beginning of the line, Terminal knows that you are looking for a command (because the syntax, or order, of command lines usually goes command -options object/target. If you typed out the command, pressing Tab twice will make Terminal suggest targets or objects of the command, such as files or folders. Either way, it will show you a list of possibilities and give you a new prompt with whatever you previously had typed so you can continue typing using one of the suggestions.
Try it now by typing cd and a space and then pressing Tab twice. You should see a list of folders, including the hidden folders in your Home folder (their names begin with a period). Now you can see that Documents does indeed have a capital D. So type cd Doc and press Tab once; Terminal will fill in uments/ as the rest of the command because Documents is the only possible match. Press Enter and you will be in your Documents folder.
Now what's so scary about that? Linux wants you to succeed and does everything it can to make working with commands easy!
Use the ls command to list your files in that folder. To go back to your Home folder, the parent of the Documents folder, we type cd .. (that's a space and two periods). The two dots are shorthand for “up one folder higher to the parent folder of this one.”
If we were buried deep in a chain of subfolders, it might be tedious to type cd .. a dozen times. We can use the Home folder's shortcut, the tilde, to go straight there by typing cd ~. Try navigating up, down and around through your Home folder and its subfolders using these commands—and remember to use the up and down arrow keys in Terminal to quickly reuse any command. We can also jump all the way to the top of the directory tree by typing cd / (the forward slash or division symbol).
Type cd / and press Enter. Now list the files and you will see a folder called home. Well, you would naturally think that is your Home folder, wouldn't you? Nope, it's a bit more tricky than that.
Remember that every user account has a personal Home folder. All of them are stored as subfolders of the top level /home folder. Type cd home, if you are currently in the root (/) directory, or cd /home to jump to where we want to go directly no matter where you are at the moment.
Now list the files and folders again. You will see a folder with your username as well as folders for any other accounts you created, such as guestuser. If you type cd yourusername you will enter your own Home folder and the prompt will turn into the tilde; remember it is like a shortcut to your own Home folder but would also be a shortcut to his or her personal Home folder for any other user who was logged in.
You've learned how to list files, in a couple of different styles, but I told you there were other options. So how do you learn what they are? You could buy a book on Linux or read more articles like this online. Or you can just ask Linux, the user friendly operating system.
If you don't remember the many options or structure of a command, just add --help to the bare command (that's a space and two hyphens before help). Try it with the list files command: ls --help. You will see it dumps a lot of info in the window, a sort of barebones listing of the command structure and options. There's another way to get more thorough information and that is by using the command to display pages of the built-in Linux manual. Try entering this man ls (man is short for manual).
Navigate through the manual entry with page up/down, up/down arrow keys, spacebar and Enter. When you've seen enough, press q to quit the manual and return to normal Terminal mode.
That's all well and good but what if you don't remember the command itself? Or if you have never even seen the command once but you know you want to do something?
Again, Linux has the right tool for you.
Let's say we want to find a command in reference to copying files from one folder to another. Apropos is a French word meaning “in reference to” and it just happens to be a Linux command line tool as well. So we type apropos copy and press Enter and a number of commands pop onto the screen—it looks like cp might be the one we want. Thanks, apropos!
Just add a word or term after apropos and it will search for commands that have that term in their description. Then you can use the man [command] pages or the [command] --help option to read more information. Now use man or the --help option with cp to read about it—yup, it's what we need to copy some files.
When you've played around enough, close Terminal with the Close button or type exit in the window.
In Part II of this article, we will do some real work using the command line rather than just learning about how it works and how to get help with it. For now, you may want to use apropos to search for interesting commands and then read more about them using man. We will use some sample files in the next episode so if you didn't already create them, review my previous article and do so while waiting for Part II.
This is my fifth article in a series about Linux. In previous articles, we took a quick tour of Linux Mint to get an overview, learned how to test drive it on our computers free of commitment or cost, went step by step through the process of installing Linux Mint, and learned about users, groups, and permissions. If you missed those articles, you can catch up by reading our group blog of Linux users, Tuxville. Visit the blog regularly to keep abreast of future articles in this series.