-->
Previous | Table of Contents | Next |
You now get a listing with many more details about the files. (These will be explained in Chapter 8, Using the File System.) The l option can be used by itself; ls -l gives detailed descriptions of files that dont begin with a period. Sometimes filenames are so long they dont fit on a single line; Linux simply wraps the remainder to the next line.
Note:
Strictly speaking, the hyphen (-) is not part of the command option. The hyphen simply tells Linux to understand each letter immediately following it as a command option. There must be a space before the hyphen, and there must not be a space between the hyphen and the letter or letters making up the command option. There must be a space after the command option if anything else is to be entered on the command line after it.You can type more than one command option after the hyphen, as we did with ls -al. In this case, we are specifying both the a and the l options. The order in which you specify options usually doesnt matter; ls -al gives the same results as ls -la. Combining options doesnt work with all Linux commands; it works only with those that use a single letter to specify each option.
Multiple options can also be specified individually, with each option preceded by a hyphen and separated from other options by spacesfor example, ls -a -l. This is usually done only when a particular option requires a further parameter.
By default, ls lists files in alphabetical order. Sometimes you may be more interested in when a file was created or last modified. The t option tells ls to sort files by date instead of alphabetically by filename, showing the newest files first. Therefore, when you enter ls -alt, you see the following:
darkstar:~$ ls -alt total 10 drwxr-xr-x 3 fido users 1024 Jan 2 13:48 ./ -rw-r--r-- 1 fido users 333 Dec 21 22:11 .bash_history drwxr-xr-x 6 root root 1024 Dec 14 01:39 ../ -rw-r--r-- 1 fido users 163 Dec 7 14:31 .kermrc drwxr-xr-x 2 fido users 1024 Dec 7 13:36 .term/ -rw-r--r-- 1 fido users 3016 May 13 1994 .emacs -rw-r--r-- 1 fido users 114 Nov 23 1993 .lessrc -rw-r--r-- 1 fido users 34 Jun 6 1993 .less
The r option tells ls to produce a reverse output. This is often used with the t option. The following is an example of what displays when you enter ls -altr:
darkstar:~$ ls -altr total 10 -rw-r--r-- 1 fido users 34 Jun 6 1993 .less -rw-r--r-- 1 fido users 114 Nov 23 1993 .lessrc -rw-r--r-- 1 fido users 3016 May 13 1994 .emacs drwxr-xr-x 2 fido users 1024 Dec 7 13:36 .term/ -rw-r--r-- 1 fido users 163 Dec 7 14:31 .kermrc drwxr-xr-x 6 root root 1024 Dec 14 01:39 ../ -rw-r--r-- 1 fido users 333 Dec 21 22:11 .bash_history drwxr-xr-x 3 fido users 1024 Jan 2 13:48 ./
Many other options can be used with ls, although you have just worked with the most commonly used ones. The important thing to remember is that you can usually customize a Linux command by using one or more command options.
Note:
With the basic Linux commands, case is important! For instance, ls has an R option (recursive: show files in subdirectories, too) which gives much different results from the r option.
Tip:
You can think of a as the all files option, l as the long list option, t as the sort by time option, r as the reverse sort option, and so on. In fact, most options in Linux are mnemonicthe option letter stands for a word or phrase. Some option letters mean the same thing in many different Linux commands. For instance, v often means verbosein other words, Give me lots of detail.However, do not assume that on an unfamiliar command certain options will work in the usual way! For instance, r is the recursive option for many Linux commands; however, in the case of ls, reverse sort is more commonly used, and therefore it gets the easier-to-type lowercase r, while recursive is left with the capital R. It might seem like not much extra effort to press the Shift key to get the capital letter, but try typing a string of four or five options, one of which is capitalized!
Linux commands often use parameters that are not actual command options. These parameters, such as filenames or directories, are not preceded by a hyphen.
For instance, by default ls lists the files in your current directory. You can, however, tell ls to list the files in any other directory simply by adding the directory to the command line. For instance, ls /bin lists everything in the /bin directory. This can be combined with command options, so that ls -l /bin gives you detailed listings of the files in /bin. Try this. You will be impressed by the number of files in the /bin directory!
You can also specify ls to list information about any particular file by entering its filename. For instance, ls -la .lessrc displays detailed information only about the .lessrc file. If the file doesnt exist, Linux doesnt show anything.
Previous | Table of Contents | Next |