Index
[]tar command [See .]
Index
[]
Index
[][See also info command, man command.]manpages [See .]command aliases [See .] Common Unix Printing System [See .].]
Index
[]CUPScontents of, listing [See .]ownerships [See .]permissions [See .]
Index
[]
Index
[]archiving [See .]finding [See .]listing [See .]ownerships [See .]permissions [See .]searching in [See .]
Index
[]
Index
[]
Index
[].] installing software [See .]
Index
[]
Index
[]
Index
[]
Index
[].][See also man command.]
Index
[]network configuration [See .]remote logins [See .]wireless interfaces [See .]with Windows machines [See .]
Index
[]
Index
[]apt [See .]handling dependencies [See .]handling dependencies [See .]CUPS [See .]
Index
[]
Index
[] remote logins [See .]
Index
[].]in files [See .] security of remote logins [See .] software installation [See .]
Index
[]
Index
[]
Index
[]
Index
[] Windows networking [See .]
Index
[].]
Index
[]
Chapter 1. Things to Know About Your Command Line
Before you really dig in to your bash shell, you first need to understand a few things that will help you as you proceed throughout this book. These are some absolutes that you just gotta know, and, trickily, some of them are not obvious at all. But after you understand them, some of the ways in which your shell behaves will start making much more sense.
Everything Is a File
On a Linux system, everything is a fileeverything, which may seem obvious at first. Of course a text document is a file, and so is an OpenOffice.org document, and don't forget a picture, an MP3, and a video. Of course!
But what about a directory? It's a file, tooa special kind of file that contains information about other files. Disk drives are really big files. Network connections are files. Even running processes are files. It's all files.
To Linux, a file is just a stream of bits and bytes. Linux doesn't care what those bits and bytes form; instead, the programs running on Linux care. To Linux, a text document and a network connection are both files; it's your text editor that knows how to work with the text document, and your Internet applications that recognize the network connection.
Throughout this book I'm going to refer to files. If it's appropriate, feel free to read that as "files and directories and subdirectories and everything else on the system." In particular, many of the commands I'll cover work equally well on documents and directories, so feel free to try out the examples on both.
Maximum Filename Lengths
People who can look back to using MS-DOS (shudder!) remember that filenames could be no longer than eight characters, plus a three-letter extension, giving you incredibly descriptive names such as MSRSUME1.DOC . Pre-OS X Macs, on the other hand, extended that limit to 31 characters, which might sound long but could still produce some odd-looking names.
Linux (and Unix) filenames can be up to 255 characters in length. That's an outrageous length for a filename, and if you're getting anywhere even close to that, your picture should appear next to verbose in the dictionary. You're given up to 255 characters, so feel free to be descriptive and accurate, but don't go nuts.
In fact, it's a good idea to keep filenames below 80 characters because that's the width of your average terminal and your filenames will appear on one line without wrapping. But that's just advice, not a requirement. The freedom to describe a file in 200+ characters is yours; just use it wisely.
Names Are Case-Sensitive
Unlike Windows and Mac OS machines, Linux boxes are case-sensitive when it comes to filenames. You could find the three following files in the same directory on a computer running Linux:
bookstobuy.txt
BooksToBuy.txt
BoOkStObUy.txt
To the Linux filesystem, those are three completely different files. If you were on Windows or Mac OS, however, you would be asked to rename or cancel your attempt to add BooksToBuy.txt to a directory that already contained bookstobuy.txt .
Case-sensitivity also means that commands and filenames must be entered exactly to match their real command names or filenames. If you want to delete files by running rm , you can't type in RM or Rm or rM . rm is it. And if you want to delete bookstobuy.txt and you instead enter rm BooksToBuy.txt , you just removed the wrong file or no file at all.
The lesson is twofold: Linux forces you to be precise, but precision is a good thing. At the same time, you're given a degree of flexibility that you won't find in other operating systems. That combination of required precision and flexibility is one of the things that makes Linux fun to use, yet understandably a bit confusing for new users.
Special Characters to Avoid in Names
Every operating system has certain no-no's when it comes to the characters you can use when naming files and directories. If you use Mac OS, the colon ( : ) isn't allowed; Windows users, on the other hand, can't use the backslash ( \ ). Linux has its verboten characters as well. Before looking at those, however, here are the characters that are always safe: numbers, letters (either uppercase or lowercase), dots ( . ), and underscores ( _ ). Other items on your keyboard might work perfectly, others might work but present complications due to the fact that your shell will try to interpret them in various ways, and some won't work at all.
/ is never an option because that particular character is used to separate directories and files. Let's say you want to keep a file listing books you want to buy. You somehow manage to name the file books/to_buy.txt (with a forward slash) to distinguish it from books/on_loan.txt and books/lost.txt . Now when you try to refer to your file at /home/scott/documents/books/to_buy.txt , your command isn't going to work because your shell thinks that a books directory is inside the documents directory, but it doesn't exist.
Instead of a forward slash, use an underscore (as I did for the to_buy part of the filename), or cram the words together (as in booksToBuy.txt or BooksToBuy.txt ).
You could use a dash, forming books-to-buy.txt , but I find that underscores work nicely as word separators while remaining more unobtrusive than dashes. If you do use a dash, though, do not place it at the beginning of a filename, as in -books_to_buy.txt , or after a space, as in books - to buy . As you're going to see later, if ," the rm command deletes files, but if you tried typing rm -books_to_buy.txt , your shell would complain with the following error message:
rm: invalid option -- b
You can use spaces if you'd like, forming books to buy.txt , but you have to let your shell know that those spaces are part of the filename. Your shell usually sees a space as a separator between arguments. Attempts to delete books to buy.txt confuses the shell, as it would try to delete a file named books , then one named to , and finally one named buy.txt . Ultimately, you won't delete books to buy.txt , and you might accidentally delete files you didn't want to remove.
So how do you work with spaces in filenames? Or the * and ? characters, which you'll learn more about in the next section? Or the ' and " characters, which also have special meanings in your shell? You have several choices. Avoid using them, if at all possible. Or escape them by placing a \ in front of the characters, which tells the shell that it should ignore their special usage and treat them as simple characters. It can grow tiresome, however, making sure that \ is in its proper place all the time: