Listing Directories and Files with ls (More Goodies)


Listing Directories and Files with ls (More Goodies)

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).

    Figure 2.1. Use ls -l to get extra information about the directories and files in a specific directory.

  • 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.

To list filenames and information:

  • 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)

      Code Listing 2.5. If you want to see hidden files, use ls -a.

      $ ls -a .    .stats  deb.schedule  other ..   current  new.ideas schedule 

      Code Listing 2.6. Use ls -l to see a listing of the contents of a directory in long format.

      $ 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.

To list all files in a directory:

  • 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.


Code Listing 2.7. If you want to see everything, use ls -la.

$ 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 $ 




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net