3.14. Listing the Contents of a Directory: lsOnce the "heart" file was created, I wanted to confirm its existence in my home directory and see how many bytes of storage it used. To do this, I used the ls utility, which lists information about a file or a directory. Figure 3-14 describes how ls works.
Some of the ls options described in Figure 3-14 won't mean a lot right now, but will become increasingly relevant as this book progresses. Here's an example of ls: $ ls ...list all files in current directory. heart $ ls -lG heart ...long listing of 'heart'. -rw-r--r-- 1 glass 106 Jan 30 19:46 heart $ _ I'll describe the exact meaning of each field in the long directory listing later in this chapter, but for now I'll give you a brief overview (Figure 3-15).
You may obtain even more information by using additional options: $ ls -alFs ...extra-long listing of current dir. total 3 ...total number of blocks of storage. 1 drwxr-xr-x 3 glass cs 512 Jan 30 22:52 ./ 1 drwxr-xr-x 12 root cs 1024 Jan 30 19:45 ../ 1 -rw-r--r-- 1 glass cs 106 Jan 30 19:46 heart $ _ The -s option generates an extra first field, which tells you how many disk blocks the file occupies. On my Linux system, each disk block is 1024 bytes long, which implies that my 106-byte file actually takes up 1024 bytes of physical storage. This is a result of the physical implementation of the file system, which is described in Chapter 13, "Linux Internals." The -a option causes ls to include a listing of all hidden files, which are files whose name begins with a period. "." and ".." are hidden files that correspond to the current directory and its parent directory, respectively. The -F option appends a / to all files that are directories. |