The ls command brings with it a lot to discuss. I haven't yet described the options to ls, yet we have already used this command and the -l option as part of the file command discussion. You can't do much on a UNIX system without ls , so I'll cover it now. The best way to cover the most important options to ls is to show examples. I do just that in the upcoming description of the ls command. lsThe following is an example of ls without any options other than the directory to list: # ls /home/denise 27247b.exe 410pt1.exe 410pt2.exe 41ndir.exe 41nds1.exe 41nds4.exe 41nwad.exe 41rtr2.exe HPDA1.EXE Mail N3212B6.EXE SCSI4S.EXE clean clean2 clean3 content.exe dsenh.exe eg1 eg2 en0316bz.exe en0316tb.exe explore.exe flexi_cd.exe fred.h hal.c hpdl0117.exe hpdlinst.txt hpux.patches j2577a.exe ja95up.exe msie10.exe n32e12n.exe nfs197.exe pass.sb plusdemo.exe ps4x03.exe psg quik_res.exe rclock.exe rkhelp.exe roni.mak sb.txt smsup2.exe softinit.remotesoftcm srvpr.exe steve.h target.exe tcp41a.exe tnds2.exe upgrade.exe whoon win95app.exe total 46718 Which of these are files? Which are directories? Have all of the entries been listed? There are many options to ls that will answer these questions. There is not a lot of information reported as a result of having issued this command. ls lists the contents of the directory specified, or the current working directory if no directory is specified. ls -aTo list all the entries of a directory, you would use the -a option. Files that begin with a "." are called hidden files and are not usually listed with ls . The following example shows the output of ls -a : $ ls -a /home/denise .Xauthority .cshrc .dt .dtprofile .elm .exrc .fmrc.orig .glancerc .gpmhp .history .login .lrom .mailrc .netscape-bookmarks.html .netscape-cache .netscape-cookies .netscape-history .netscape-newsgroups-news.spry.com .netscape-newsgroups-newsserv.hp.com .netscape-preferences .newsrc-news.spry.com .newsrc-newsserv.hp.com .profile .rhosts .sh_history .softbuildrc .softinit.orig .sw .xinitrc .xsession 27247b.exe 410pt1.exe 410pt2.exe 41ndir.exe 41nds1.exe 41nds4.exe 41nwad.exe 41rtr2.exe HPDA1.EXE Mail N3212B6.EXE SCSI4S.EXE clean clean2 clean3 content.exe dsenh.exe eg1 eg2 en0316bz.exe en0316tb.exe explore.exe flexi_cd.exe fred.h hal.c hpdl0117.exe hpdlinst.txt hpux.patches j2577a.exe ja95up.exe msie10.exe n32e12n.exe nfs197.exe pass.sb plusdemo.exe ps4x03.exe psg quik_res.exe rclock.exe rkhelp.exe roni.mak sb.txt smsup2.exe softinit.remotesoftcm srvpr.exe steve.h target.exe tcp41a.exe tnds2.exe upgrade.exe whoon win95app.exe total 46718 Notice that this output includes hidden files, those that begin with a ".", as well as all other files listed with just ls . These did not appear when ls was issued without the -a option. All subsequent examples include the -a option. ls -lTo list all information about the contents of directory, you use the -l option to ls , as shown in the following example (some of these file names were shortened to fit on the page): $ ls -al /home/denise -rw------- 1 denise users 98 Oct 6 09:19 .Xauthority -r--r--r-- 1 denise users 814 May 19 10:10 .cshrc drwxr-xr-x 7 denise users 1024 Sep 26 11:14 .dt -rwxr-xr-x 1 denise users 8705 Jul 7 12:04 .dtprofile drwx------ 2 denise users 1024 Jul 31 18:48 .elm -r--r--r-- 1 denise users 347 May 19 10:10 .exrc -rwxrwxrwx 1 denise users 170 Jun 6 14:20 .fmrc.orig -rw------- 1 denise users 97 Jun 12 18:59 .glancerc -rw------- 1 denise users 17620 Sep 21 16:11 .gpmhp -rwxr-xr-x 1 denise users 391 Sep 19 09:55 .history -r--r--r-- 1 denise users 341 May 19 10:10 .login drwx--x--x 2 denise users 1024 Jul 31 18:48 .lrom -rw-r--r-- 1 denise users 768 Jul 28 12:54 .mailrc -rw------- 1 denise users 1450 Oct 6 13:58 .netscape-bookmarks.html drwx------ 2 denise users 10240 Oct 10 15:24 .netscape-cache -rw------- 1 denise users 91 Sep 18 14:16 .netscape-cookies -rw------- 1 denise users 43906 Oct 10 15:32 .netscape-history -rw-r--r-- 1 denise users 566 Aug 25 14:36 .netscape--news.spry.com -rw------- 1 denise users 46514 Jun 28 12:35 .netscape-.hp.com -rw------- 1 denise users 1556 Sep 28 15:02 .netscape-preferences -rw------- 1 denise users 104 Jul 11 11:01 .newsrc-news.spry.com -rw-r--r-- 1 denise users 223 Sep 26 13:26 .newsrc-newv.hp.com -r--r--r-- 1 denise users 446 May 19 10:10 .profile -rw------- 1 denise users 21 Jul 6 13:21 .rhosts -rw------- 1 denise users 2328 Oct 10 15:22 .sh_history -rw-r--r-- 1 denise users 1052 Sep 22 15:00 .softbuildrc -rwxrwxrwx 1 denise users 161 Jul 11 12:19 .softinit.orig drwxr-xr-x 3 denise users 1024 Aug 31 15:44 .sw -rw------- 1 denise users 23 Jun 2 15:01 .xinitrc -rwxr-xr-x 1 denise users 11251 May 19 10:41 .xsession -rw-r--r-- 1 denise users 611488 Oct 3 12:00 27247b.exe -rw-r--r-- 1 denise users 114119 Sep 29 12:49 410pt1.exe -rw-r--r-- 1 denise users 136979 Sep 29 12:53 410pt2.exe -rw-r--r-- 1 denise users 173978 Sep 29 12:40 41ndir.exe -rw-r--r-- 1 denise users 363315 Sep 29 12:52 41nds1.exe -rw-r--r-- 1 denise users 527524 Sep 29 12:57 41nds4.exe -rw-r--r-- 1 denise users 1552513 Sep 29 12:50 41nwad.exe -rw-r--r-- 1 denise users 853424 Sep 29 12:24 41rtr2.exe -rw-r--r-- 1 denise users 1363011 Sep 20 12:20 HPDA1.EXE drwx------ 2 denise users 24 Jul 31 18:48 Mail -rw-r--r-- 1 denise users 1787840 Aug 31 09:35 N3212B6.EXE -rw-r--r-- 1 denise users 13543 Sep 23 09:46 SCSI4S.EXE -rw-r--r-- 1 denise users 28395 Aug 30 15:07 cabview.exe -rwx--x--x 1 denise users 66 Jun 8 17:40 clean -rwx--x--x 1 denise users 99 Jun 20 17:44 clean2 -rwx--x--x 1 denise users 66 Jun 20 17:51 clean3 -rw-r--r-- 1 denise users 15365 Aug 30 15:07 content.exe -rw-r--r-- 1 denise users 713313 Sep 29 12:56 dsenh.exe -rwx------ 1 denise users 144 Aug 14 17:10 eg1 -rwx------ 1 denise users 192 Aug 15 12:13 eg2 -rw-r--r-- 1 denise users 667890 Sep 20 12:41 en0316bz.exe -rw-r--r-- 1 denise users 641923 Sep 20 12:42 en0316tb.exe -rw-r--r-- 1 denise users 6251 Aug 30 15:07 explore.exe -rw-r--r-- 1 denise users 23542 Aug 30 15:08 flexi_cd.exe -rw-r--r-- 1 denise users 30 Aug 14 17:02 fred.h -rw-r--r-- 1 denise users 0 Aug 14 17:24 hal.c -rw-r--r-- 1 denise users 895399 Sep 20 12:32 hpdl0117.exe -rw-r--r-- 1 denise users 14135 Sep 20 12:39 hpdlinst.txt -rw------- 1 denise users 2943 Jun 19 14:42 hpux.patches -rw-r--r-- 1 denise users 680279 Sep 20 12:26 j2577a.exe -rw-r--r-- 1 denise users 930728 Sep 20 15:16 ja95up.exe -rw-r--r-- 1 denise users 53575 Oct 10 10:37 mbox -rw-r--r-- 1 denise users 1097728 Aug 30 15:03 msie10.exe -rw-r--r-- 1 denise users 1790376 Sep 18 14:32 n32e12n.exe -rw-r--r-- 1 denise users 1393835 Sep 29 12:59 nfs197.exe -rw------- 1 denise users 977 Jul 3 14:25 pass.sb -rw-r--r-- 1 denise users 1004544 Aug 30 15:00 plusdemo.exe -rw-r--r-- 1 denise users 229547 Sep 29 12:27 ps4x03.exe -rwxr--r-- 1 denise users 171 Aug 9 13:43 psg -rw-r--r-- 1 denise users 16645 Aug 30 15:08 quik_res.exe -rw-r--r-- 1 denise users 14544 Aug 30 15:08 rclock.exe -rw-r--r-- 1 denise users 2287498 Aug 30 15:12 rkhelp.exe -rw-r--r-- 1 denise users 0 Aug 15 12:10 roni.mak -rw-r--r-- 1 denise users 1139 Sep 28 10:35 sb.txt -rw-r--r-- 1 denise users 569855 Sep 29 12:55 smsup2.exe -rw------- 1 root sys 161 Jul 11 12:18 softinit.remotesoftcm -rw-r--r-- 1 denise users 39 Sep 29 12:48 srvpr.exe -rw-r--r-- 1 denise users 38 Aug 15 12:14 steve.h -rw-r--r-- 1 denise users 14675 Aug 30 15:08 target.exe -rw-r--r-- 1 denise users 229630 Sep 29 12:54 tcp41a.exe -rw-r--r-- 1 denise users 1954453 Sep 29 12:26 tnds2.exe -rw-r--r-- 1 denise users 364270 Sep 23 09:50 upgrade.exe -rwx-----x 1 denise users 88 Aug 9 13:43 whoon -rw-r--r-- 1 denise users 191495 Aug 30 15:00 win95app.exe total 46718 Because I find this to be the most commonly used option with the ls command, I describe each of the fields produced by ls -l . I'll use the earlier example of the ls -l command, which showed only one file when describing the fields: $ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort The first field defines the access rights of the file, which I cover in "Permissions" in the next chapter. The owner has read, write, and execute permissions on the file. The group has read and execute permissions on the file. other has execute permissions. The second field is the link count. This lists how many files are symbolically linked to the file. We will get into the details of the ln command used to link files later. In this case, the link count is 1 , which means that this file is linked only to itself. For directories such as .dt shown below, the number of subdirectories is shown rather than the link count. This number includes one for the directory itself as well as one for the parent directory. This means that a total of five directories are below .dt . drwxr-x--x 7 denise users 1024 Jul 26 10:20 .dt The subdirectories below /home/denise/.dt are:
These five subdirectories plus the directory itself and the parent directory make a total of seven. The third field lists the owner of the file. Your login name , such as denise , is listed here. When you create a file, your login name is listed by default as the owner of the file. The fourth field lists the group to which the file belongs. Groups are covered in the next chapter in "Permissions." The fifth field shows the size of the file. The file sort is 120 bytes in size. The sixth field (which includes a date and time such as Jul 26 10:20 ) lists the date and time the file was created or last changed. The seventh field lists the files and directories in alphabetical order. You first see the files that begin with a ".", then the files that begin with numbers , then the files that begin with uppercase letters, and finally the files that begin with lower case letters . There are a lot of characters that a file can begin with in UNIX, so if you perform an ls -l and don't see the file you are looking for, it may appear at a different spot in the listing from what you expected. ls -iTo get information about the inode of a file, you use the -i option to ls . The following example includes both the -i and -l options to ls : $ ls -ail /home/denise 137717 -rw------- 1 denise users 98 Oct 6 09:19 .Xauthority 137623 -r--r--r-- 1 denise users 814 May 19 10:10 .cshrc 140820 drwxr-xr-x 7 denise users 1024 Sep 26 11:14 .dt 137629 -rwxr-xr-x 1 denise users 8705 Jul 7 12:04 .dtprofile 180815 drwx------ 2 denise users 1024 Jul 31 18:48 .elm 137624 -r--r--r-- 1 denise users 347 May 19 10:10 .exrc 137652 -rwxrwxrwx 1 denise users 170 Jun 6 14:20 .fmrc.orig 137650 -rw------- 1 denise users 97 Jun 12 18:59 .glancerc 137699 -rw------- 1 denise users 17620 Sep 21 16:11 .gpmhp 137640 -rwxr-xr-x 1 denise users 391 Sep 19 09:55 .history 137625 -r--r--r-- 1 denise users 341 May 19 10:10 .login 185607 drwx--x--x 2 denise users 1024 Jul 31 18:48 .lrom 137642 -rw-r--r-- 1 denise users 768 Jul 28 12:54 .mailrc 137641 -rw------- 1 denise users 1450 Oct 6 13:58 .netscaperks.html 179207 drwx------ 2 denise users 10240 Oct 10 15:24 .netscape-cache 137656 -rw------- 1 denise users 91 Sep 18 14:16 .netscape-cookies 137635 -rw------- 1 denise users 43906 Oct 10 15:32 .netscape-history 137645 -rw-r--r-- 1 denise users 566 Aug 25 14:36 .netscapes.spry.com 137646 -rw------- 1 denise users 46514 Jun 28 12:35 .netsca 137634 -rw------- 1 denise users 1556 Sep 28 15:02 .netscaperences 137637 -rw------- 1 denise users 104 Jul 11 11:01 .newsrcws.spry.com 137633 -rw-r--r-- 1 denise users 223 Sep 26 13:26 .newsrc-hp.com 137626 -r--r--r-- 1 denise users 446 May 19 10:10 .profile 137649 -rw------- 1 denise users 21 Jul 6 13:21 .rhosts 137694 -rw------- 1 denise users 2328 Oct 10 15:22 .sh_history 137698 -rw-r--r-- 1 denise users 1052 Sep 22 15:00 .softbuildrc 137636 -rwxrwxrwx 1 denise users 161 Jul 11 12:19 .softinit.orig 33600 drwxr-xr-x 3 denise users 1024 Aug 31 15:44 .sw 137648 -rw------- 1 denise users 23 Jun 2 15:01 .xinitrc 137628 -rwxr-xr-x 1 denise users 11251 May 19 10:41 .xsession 137715 -rw-r--r-- 1 denise users 611488 Oct 3 12:00 27247b.exe 137707 -rw-r--r-- 1 denise users 114119 Sep 29 12:49 410pt1.exe 137710 -rw-r--r-- 1 denise users 136979 Sep 29 12:53 410pt2.exe 137705 -rw-r--r-- 1 denise users 173978 Sep 29 12:40 41ndir.exe 137709 -rw-r--r-- 1 denise users 363315 Sep 29 12:52 41nds1.exe 137714 -rw-r--r-- 1 denise users 527524 Sep 29 12:57 41nds4.exe 137708 -rw-r--r-- 1 denise users 1552513 Sep 29 12:50 41nwad.exe 137696 -rw-r--r-- 1 denise users 853424 Sep 29 12:24 41rtr2.exe 137654 -rw-r--r-- 1 denise users 1363011 Sep 20 12:20 HPDA1.EXE 182429 drwx------ 2 denise users 24 Jul 31 18:48 Mail 137683 -rw-r--r-- 1 denise users 1787840 Aug 31 09:35 N3212B6.EXE 137702 -rw-r--r-- 1 denise users 13543 Sep 23 09:46 SCSI4S.EXE 137638 -rwx--x--x 1 denise users 66 Jun 8 17:40 clean 137651 -rwx--x--x 1 denise users 99 Jun 20 17:44 clean2 137632 -rwx--x--x 1 denise users 66 Jun 20 17:51 clean3 137688 -rw-r--r-- 1 denise users 15365 Aug 30 15:07 content.exe 137713 -rw-r--r-- 1 denise users 713313 Sep 29 12:56 dsenh.exe 137667 -rwx------ 1 denise users 144 Aug 14 17:10 eg1 137671 -rwx------ 1 denise users 192 Aug 15 12:13 eg2 137662 -rw-r--r-- 1 denise users 667890 Sep 20 12:41 en0316bz.exe 137665 -rw-r--r-- 1 denise users 641923 Sep 20 12:42 en0316tb.exe 137689 -rw-r--r-- 1 denise users 6251 Aug 30 15:07 explore.exe 137690 -rw-r--r-- 1 denise users 23542 Aug 30 15:08 flexi_cd.exe 137670 -rw-r--r-- 1 denise users 30 Aug 14 17:02 fred.h 137673 -rw-r--r-- 1 denise users 0 Aug 14 17:24 hal.c 137660 -rw-r--r-- 1 denise users 895399 Sep 20 12:32 hpdl0117.exe 137661 -rw-r--r-- 1 denise users 14135 Sep 20 12:39 hpdlinst.txt 137647 -rw------- 1 denise users 2943 Jun 19 14:42 hpux.patches 137659 -rw-r--r-- 1 denise users 680279 Sep 20 12:26 j2577a.exe 137697 -rw-r--r-- 1 denise users 930728 Sep 20 15:16 ja95up.exe 137684 -rw-r--r-- 1 denise users 1097728 Aug 30 15:03 msie10.exe 137658 -rw-r--r-- 1 denise users 1790376 Sep 18 14:32 n32e12n.exe 137643 -rw-r--r-- 1 denise users 1393835 Sep 29 12:59 nfs197.exe 137639 -rw------- 1 denise users 977 Jul 3 14:25 pass.sb 137664 -rw-r--r-- 1 denise users 1004544 Aug 30 15:00 plusdemo.exe 137704 -rw-r--r-- 1 denise users 229547 Sep 29 12:27 ps4x03.exe 137666 -rwxr--r-- 1 denise users 171 Aug 9 13:43 psg 137691 -rw-r--r-- 1 denise users 16645 Aug 30 15:08 quik_res.exe 137692 -rw-r--r-- 1 denise users 14544 Aug 30 15:08 rclock.exe 137693 -rw-r--r-- 1 denise users 2287498 Aug 30 15:12 rkhelp.exe 137669 -rw-r--r-- 1 denise users 0 Aug 15 12:10 roni.mak 137657 -rw-r--r-- 1 denise users 1139 Sep 28 10:35 sb.txt 137712 -rw-r--r-- 1 denise users 569855 Sep 29 12:55 smsup2.exe 137644 -rw------- 1 root sys 161 Jul 11 12:18 softinittesoftcm 137706 -rw-r--r-- 1 denise users 39 Sep 29 12:48 srvpr.exe 137682 -rw-r--r-- 1 denise users 38 Aug 15 12:14 steve.h 137685 -rw-r--r-- 1 denise users 14675 Aug 30 15:08 target.exe 137711 -rw-r--r-- 1 denise users 229630 Sep 29 12:54 tcp41a.exe 137700 -rw-r--r-- 1 denise users 1954453 Sep 29 12:26 tnds2.exe 137703 -rw-r--r-- 1 denise users 364270 Sep 23 09:50 upgrade.exe 137663 -rwx-----x 1 denise users 88 Aug 9 13:43 whoon 137678 -rw-r--r-- 1 denise users 191495 Aug 30 15:00 win95app.exe The inode number contains the following: the location of files and directories on the disk; access permissions; owner and group IDs; file link count; time of last modification; time of last access; device identification number for special files; and a variety of other information. inode numbers are used extensively by the system as you change directories and perform various tasks . ls -pBecause you may have subdirectories within the directory you are listing, you may want to use the -p option to ls, which puts a "/" (slash) in after directory names, as shown in the following example: $ ls -ap /home/denise .Xauthority .cshrc .dt/ .dtprofile .elm/ .exrc .fmrc.orig .glancerc .gpmhp .history .login .lrom/ .mailrc .netscape-bookmarks.html .netscape-cache/ .netscape-cookies .netscape-history .netscape-newsgroups-news.spry.com .netscape-newsgroups-newsserv.hp.com .netscape-preferences .newsrc-news.spry.com .newsrc-newsserv.hp.com .profile .rhosts .sh_history .softbuildrc .softinit.orig .sw/ .xinitrc .xsession 27247b.exe 410pt1.exe 410pt2.exe 41ndir.exe 41nds1.exe 41nds4.exe 41nwad.exe 41rtr2.exe HPDA1.EXE Mail/ N3212B6.EXE SCSI4S.EXE clean clean2 clean3 content.exe dsenh.exe eg1 eg2 en0316bz.exe en0316tb.exe explore.exe flexi_cd.exe fred.h hal.c hpdl0117.exe hpdlinst.txt hpux.patches j2577a.exe ja95up.exe msie10.exe n32e12n.exe nfs197.exe pass.sb plusdemo.exe ps4x03.exe psg quik_res.exe rclock.exe rkhelp.exe roni.mak sb.txt smsup2.exe softinit.remotesoftcm srvpr.exe steve.h target.exe tcp41a.exe tnds2.exe upgrade.exe whoon win95app.exe ls -RBecause the subdirectories you are listing probably have files and subdirectories beneath them, you may want to recursively list these. The -R option to ls shown in the following example performs this recursive listing. This listing is truncated because it would be too long if it included all the subdirectories under /home/denise : $ ls -aR /home/denise .Xauthority .cshrc .dt .dtprofile .elm .exrc .fmrc.orig .glancerc .gpmhp .history .login .lrom .mailrc .netscape-bookmarks.html .netscape-cache .netscape-cookies .netscape-history .netscape-newsgroups-news.spry.com .netscape-newsgroups-newsserv.hp.com .netscape-preferences .newsrc-news.spry.com .newsrc-newsserv.hp.com .profile .rhosts .sh_history .softbuildrc .softinit.orig .sw .xinitrc .xsession 27247b.exe 410pt1.exe 410pt2.exe 41ndir.exe 41nds1.exe 41nds4.exe 41nwad.exe 41rtr2.exe HPDA1.EXE Mail N3212B6.EXE SCSI4S.EXE clean clean2 clean3 content.exe dsenh.exe eg1 eg2 en0316bz.exe en0316tb.exe explore.exe flexi_cd.exe fred.h . . (skip some of the listing) . /home/denise/.lrom: LRAAAa27637.CC LRBAAa27637.CC LROM.AB LROM.AB.OLD LROM.AB.lk1 LROM.SET /home/denise/.netscape-cache: cache306C05510015292.gif cache306C05560025292.gif cache306C05560035292.gif /home/denise/.sw: sessions . . (skip remainder of the listing) . ls SummaryI have shown you what I believe to be the most important, and most often used, ls options. Because you may have future needs to list files and directories based on other criteria, I provide you with a list of most ls options. There is no substitute, however, for issuing the man ls command. Whatever I provide is only a summary. Viewing the man pages for ls gives you much more information. The following is a summary of the more commonly used ls options: ls - List the contents of a directory
Also, some shorthand command names are available for issuing ls with options. For instance, ll is equivalent to ls -l , and lsr is equivalent to ls -R in some UNIX variants. We will also cover creating an "alias," whereby you can define your own shorthand for any command in an upcoming chapter. |