First Steps
Linux Mint users will find the Terminal program in the Accessories group in the programs menu. It starts quickly enough, but this is where the first question arises: "What in the name of Pete is this?"
darkwyrm@onyx ~ $∎
This is known as the prompt. It shows the name of the current user and the name of the computer the user is logged into. This is normally the name of the computer you are using, also known as the hostname. The tilde character (~) is shorthand for your home folder, which is normally the location /home/myusername. In this case, the home folder is /home/darkwyrm. Folders are listed in succession, separated by a forward slash character (/). The dollar sign is just a separator between the prompt and the blinking cursor. At this point, the computer is waiting for you to tell it what to do.
Issuing commands in the Terminal are just a matter of typing them in and pressing Enter. The trick, therefore, is knowing what commands are available and how to use them. Let's start by just getting around.
cd path - Change directory. Go to a different folder. Use two periods (..) to mean the parent directory.
- cd /etc - change to the top-level folder etc.
- cd /var/www - change to the www folder in the top-level folder var.
- cd ../cache - go up into the parent folder and then down into the subfolder cache.
- cd ~/Music/Skillet - Go the home folder, then Music, and then finally land in the Skillet folder.
ls <pattern> - List. This shows the contents of a directory. If pattern is left out, it lists the contents of the current directory. Note that pattern is not necessarily a name. If you give ls a file name, it will print the file's name again, and if you give it the name of a directory, it will list the contents of that directory. pattern can also be a directory like you would use with the cd command.
- ls - list the contents of the current directory
- ls ~ - list the contents of the user's home directory
- ls Videos - list the contents of the Videos directory
Dealing with Special Characters
In your exploring the system with cd and ls, you may encounter instances where one of the commands doesn't work the way you might think. Consider this one:
cd Owl City
bash: cd: Owl: No such file or directory
Oops. It looks like we have a directory with a space in its name. How do we get into it? By escaping the space. In other words, we tell the command interpreter, called bash, that this is one name and not a series of them. To enter the Owl City folder, use the cd command this way:
cd Owl\ City
Voila! It's easy enough to make a man speak French against his will. The bash interpreter uses quite a few other characters for special purposes, but generally this is limited to symbols. If you are in a habit of using apostrophes in file names, be aware that you will have to escape them, as well. In fact, the only character which can't be part of a file or directory name is the forward slash. Well, actually this is only sometimes true. If you are in a habit of working with Windows files, the following characters are also not allowed:
? < > \ : * " |
The last character, called the pipe symbol, is usually found on the same key as the backslash (\) on U.S. keyboards. The rest are fairly obvious. With that said, it's probably best to choose file names with just letters, numbers, apostrophes, spaces, and underscores. It's less confusing that way.
If you have to type a path which has a lot of spaces or other special characters in it, it's much easier to put the whole thing inside a pair of single quotes, which escapes the entire thing.
cd '/home/darkwyrm/Saved Music Videos/The Making of !Hero.flv'
Tab Completion
Our final trick is the Tab key. It automatically finishes whatever you're typing in, whether it be a command name or a file or directory name. For example, if you have a directory named ThisIsAReallyLongName, you don't have to type in its full name to list its contents. Instead, you can type ls Th, press Tab, and watch how it finishes the rest. It's almost magical and it's a regular part of any bash wizard's toolkit.There is a catch to auto-completion, however: it can't read your mind. If there are two entries in your directory, one is called ThisIsAReallyLongName and another is called ThatOneIsEvenLongerThanTheFirst, pressing Tab after typing T isn't going to get you far--it will add an h and stop. At this point you can double-tap Tab to see what the choices are, or you can type the i and press Tab again to finish completing the name. Only after it is obvious to bash which name you are typing will it finish the name; otherwise it will add as much as it can and stop.
A Little History
Linux dates back to 1991, when Linus Torvalds, its author, posted its first release to the Internet. However, its workflow and design dates back to 1969, the year of the creation of UNIX at Bell Labs. In those days, computers were hulking contraptions with which people interacted by means of a terminal. These terminals were little more than a display and a keyboard, having no processing power on their own. They issued commands to the computer, which then did all the work. The Terminal program emulates this environment and adds other features, such as color, clipboard operations, and more.Why should we bother with such a dated interface? Power. The philosophy behind UNIX is one which places high value on flexibility. The design premise behind the UNIX terminal commands was that each should do one thing and do it well. They would be able to work together to accomplish a task that would be complicated to do with larger programs. Command names were kept short to save on typing. All information was either a program or a text file. Computers are used for far more kinds of work than they were then, but there are still a great many kinds of work that are most easily handled from the command line. Most people don't need to be capable of doing everything, but having a basic level of comfort with using it is well worth time spent acquiring it.
No comments:
Post a Comment