Available as PDF
ls command displays a list of
files in the specified directory. If you don't specify a directory,
then ls will list the files in the current directory.
By default, ls gives a short list, showing filenames only. It also
skips certain files (those whose names start with a
Figure 11. Output from
3dtree.jpg command_memos mj.ultra temp HTMLBgnrGuide.txt dead.letter pgpdriver unpgp News dead.letter.bak pine TUTORIAL info.listserv pinerc016899 baen.txt jim.kirk.letters print.txt bin junk public_html calendar mail rexx
The files in the preceding example are in what UNIX considers to be "alphabetical order." Actually, UNIX calls it the "collating sequence," since it takes into account the order of characters other than the familiar AZ and az alphabetic sequence. Further, since UNIX differentiates between UPPER and lower-case characters, these two sets (AZ and az) are distinguished in the collating sequence, as reflected in the order in which the files are displayed (among other things).
As you can see, in the collating sequence, numbers (numerals,
actually) come before letters. Then come the UPPER-case letters,
followed by the lower-case letters. The
formats its listing in columns, just like a phone book--you read down
each column, rather than across the page.
If you wish to see the "long" listing, which includes information about the file type, size, and access permissions, use the form:
ls <space> dash L [for Long]). Note that the
-l option must be in lower-case for
it to be recognized.
If you wish to see "all" the files, including
the special files whose names begin with
use the form
Figure 12. Output from
ls -la Command
total 1600 drwx---s-x 11 picard STAFF 1536 Jun 26 14:49 . dr-xr-sr-x1300 bin bin 20480 Jun 26 12:06 .. -rw------- 1 picard STAFF 948 Jun 06 09:46 .addressbook -rw------- 1 picard STAFF 3368 Jun 06 09:46 .addressbook.lu -rw------- 1 picard STAFF 193 Apr 02 10:06 .article -rw------- 1 picard STAFF 1035 May 20 12:30 .bash_history drwx---S-- 2 picard STAFF 512 Jun 23 13:56 .mailpgp -rw------- 1 picard STAFF 128654 Jun 10 19:19 .newsrc drwx------ 4 picard STAFF 512 May 29 07:01 .pgp -rw------- 1 picard STAFF 10196 Jun 26 14:33 .pinerc -rwxr-xr-x 1 picard STAFF 1047 May 27 14:15 .plan -rw------- 1 picard STAFF 35 Jun 17 09:23 .profile -rw------- 1 picard STAFF 371 Sep 08 1995 .signature -rw------- 1 picard STAFF 81691 Jun 20 10:34 3dtree.jpg -rw------- 1 picard STAFF 31156 Jan 03 10:19 HTMLBgnrGuide.txt drwx---s-x 2 picard STAFF 512 Apr 01 13:26 News -rw------- 1 picard STAFF 11760 Jul 23 1995 TUTORIAL -rw------- 1 picard STAFF 234 Feb 02 08:18 baen.txt drwx---s-x 2 picard STAFF 512 Mar 12 06:57 bin -rw------- 1 picard STAFF 71 Jul 31 1995 calendar -rw------- 1 picard STAFF 338912 May 02 1995 command.memos -rw------- 1 picard STAFF 747 Jun 24 13:12 dead.letter -rw------- 1 picard STAFF 10506 Jun 01 12:42 info.listserv -rw------- 1 picard STAFF 698675 Nov 01 1995 jim.kirk.letters -rw------- 1 picard STAFF 122 Jun 24 13:28 junk drwx------ 2 picard STAFF 1536 Jun 25 12:40 mail -rw-r----- 1 picard STAFF 1397 May 28 12:50 mj.ultra drwx---s-x 2 picard STAFF 512 May 26 21:09 pine -rw------- 1 picard STAFF 1716 Jul 23 1995 print.txt drwxr-sr-x 6 picard STAFF 1024 Mar 27 10:54 public_html drwx---s-x 3 picard STAFF 512 Mar 31 07:24 rexx drwx---s-x 2 picard STAFF 512 Aug 08 1995 temp -rwx--x--x 1 picard STAFF 368 May 28 14:10 unpgp
Let's look at this listing, and see what it tells us. At first
glance, the left-most column looks like utter nonsense;
drwxr--blah-blah-blah. What's going on here?
File Type. The first position/character in this column describes what
type of entry each horizontal line represents. The first character
will usually be either a
- or a
Symbols in the first (left most) position on the line represent:
= Regular File
You can tell,
just by looking at the output from
ls -l which
entries are files and which are directories.
Permissions. The rest of the first column (after the
d) indicates access permissions which
have been set either explicitly, by you, using the
command (which we'll look at later) or automatically,
by the system, when the file (or directory) was created. We'll
discuss this part of the listing in more detail when we get to the
chmod command, which deals with setting file access
Directory Entries (and Hard-Link Count). The next column (immediately to the right of the access
permissions) is a number which tells how many directory entries are
under that item. For a regular file, this will typically be
1. For a directory, this will always be at least
2. The reason for this is that every directory always
contains pointers to both itself, and its parent directory. You can
see these two entries as the first two items in our example listing
in Figure 12: the entries for
(i.e. one period, and two periods). The single period (
. ), is the pointer to the current directory--the
directory that you are "in" right now. Two periods (
.. ), point to the parent directory--the directory which
contains the current directory. You can use these as convenient
nicknames/shortcuts in some commands, when you want to describe a
Owner. The next column to the right displays the userid of the owner
of this file or directory. In our listing, most of the files are
owned by our hypothetical user,
When you create files and directories, you will be their owner, and
your userid will show here, in place of
Group. The next column (mostly "
in our example) shows the name of the user group which is connected
with this entry. Each userid is a member of one or more groups, and
access permissions may be set which determine what sort of access
other members of the same group have to the file or directory named.
Again, more on that when we get to the chmod command.
Size. The next column shows the file size in bytes (characters).
Date/Time. The next 3 columns show the date and time the file was last modified.
File Name. Finally, we have the file name. As discussed earlier, UNIX is
very accommodating with regard to the length of file names. However
there are some qualifications: File names cannot (usually) contain
blank spaces, or the characters
?. This is because
used to separate levels of a pathname,
* is a
"wildcard" character which is expanded by the system to mean
"any number of any characters," and
a wildcard representing "any single character." MS-DOS users
in particular should recognize these "wildcard" characters.
Note the first few entries in our
ls -la list
example. All the files start with
. (a period) and
none of them showed up in the "plain" ls listing we first
looked at. These are files which, normally, you would not want to be
bothered with seeing. Some of them are created by programs to contain
information about you and how you use the program--similar to
.INI" files, or the files in
a Macintosh "Preferences" folder.
Others are files that you may have created, but, for whatever reason, don't care to always have to see in your directory listing.
Later in this document we'll talk more about some of them,