If you’ve been following along, you’re probably an expert at using ls to list directory contents and to verify that files and directories were copied as you intended. ls, though, has a couple more handy uses. In particular, you can also use it to
List filenames and information, which is handy for differentiating similar files (Figure 2.1).
List all files in a directory, including hidden ones, such as .profile and .login configuration files (Code Listing 2.5). See Chapter 8 for more about configuration files.
ls -l
At the shell prompt, type ls -l (that’s a lowercase “L,” not a one). You’ll see the list of files in your directory fly by with the following information about each file (Code Listing 2.6):
Filename
File size
Date of last modification
Permissions information (find out more about permissions in Chapter 5)
Ownership and group membership (also covered in Chapter 5)
$ ls -a
. .stats deb.schedule other
.. current new.ideas schedule
|
$ ls -l
total 13
-rw-rw-r– 1 ejr users 2151 Jun 29 12:26 current
-rw-rw-r– 2 ejr users 1475 Jun 29 12:35 deb.schedule
-rw-rw-r– 1 ejr users 4567 Jun 29 12:26 new.ideas
drwxrwxr-x 2 ejr users 1024 Jun 29 13:06 other
-rw-rw-r– 1 ejr users 1475 Jun 29 12:22 schedule
|
Time of last modification (if the file’s been modified recently) or year of last modification (if the file was last modified more than six months previously). Check out touch earlier in this chapter to see how files might have modification dates in the future.
ls -la
Enter ls -a at the shell prompt to list all the files in the directory, including hidden files, with full information, as shown in Code Listing 2.7.
✓ Tips
You can hide files by giving them a name that starts with a dot (.). That is, profile would not be hidden, but .profile would be.
Remember, you can combine any flags to specify multiple options. For example, if you want to list all files (-a) in the long format (-l) you would use ls -la.
Try ls –ltR to get the complete listing of your current directory, the directories it contains, and so forth until you run out of subdirectories to descend into.
$ ls -la
total 22
drwxrwxr-x 3 ejr users 1024 Jun 29 13:07 .
drwxrwx–- 7 ejr users 1024 Jun 29 12:16 ..
-rw-rw-r– 1 ejr users 6718 Jun 29 13:00 .stats
-rw-rw-r– 1 ejr users 2151 Jun 29 12:26 current
-rw-rw-r– 2 ejr users 1475 Jun 29 12:35 deb.schedule
-rw-rw-r– 1 ejr users 4567 Jun 29 12:26 new.ideas
drwxrwxr-x 2 ejr users 1024 Jun 29 13:06 other
-rw-rw-r– 1 ejr users 1475 Jun 29 12:22 schedule
$
|