Listing Directories and Files with ls


Listing Directories and Files with ls

Your Unix system is made up of directories and files that store a variety of information, including setup information, configuration settings, programs, and options, as well as other files and directories. You might think of your Unix system as being a tree (tree roots, actually), with subdirectories stemming from higher-level directories. As shown in Figure 1.6, all of these files and directories reside within the root directory, which contains everything in the system.

Figure 1.6. All files and directories are nested within the root directory, which serves to contain everything in the system.


Using the ls command, you can find out exactly what's in your Unix system and thereby find out what's available to you. You can list the files and directories of a directory that you're currently in or a directory that you specify.

To list the files and directories of the directory you're in:

  • ls

    At the shell prompt, type ls to list the files and directories in the current directory, which in this case is our home directory (Code Listing 1.2).

Code Listing 1.2. Use ls by itself to list the files and directories of the directory you're in.

[jdoe@frazz jdoe]$ ls limerick mail/ Project/ public_html/  testfile testlink@ tmp/ [jdoe@frazz jdoe]$ 

To list the files and directories of a specified directory:

  • ls /bin

    Here, you type the ls command plus the name of a directory. As shown in Code Listing 1.3, this command lists the files and directories in the /bin directory, in which you'll find system commands and programs.

Tips

  • You can list the files and directories of the root directory at any time and in any place by typing ls /. The root directory is the highest-level directory in a Unix system; all other directories are below the root directory.

  • Can't remember that pesky filename?

    Just use ls to help jog your memory. Or, refer to Finding Forgotten Files with find in Chapter 2, which can also help you remember filenames.

  • Many other ls options are available to control the amount of information about your files that you see and the format in which they appear on screen. See Chapter 2's Listing Files and Directories with ls (More Goodies) section for details.


Code Listing 1.3. Use ls with the name of a directory to list the contents of that directory (/bin, in this case).

jdoe@frazz jdoe]$ ls /bin arch*            domainname@    ipcalc*        open*           tar* awk@             echo*          ipv6c          eys*            red@           unlink* chmod*           fbresolution*  login*         rm*             usleep* chown*           fgrep@         ls*            rmdir*          vi@ consolechars*    find*          lsb_release*   rpm*            view@ cp*              gawk*          mail*          rvi@            vim@ cpio*            gawk-3.1.1@    mkdir*         rview@ date*            gtar@          more*          sleep*          zcat* dd*              gunzip*        mount*         sort*           zsh* df*              gzip*          mv*            stat* dmesg*           hostname*      netstat*       stty* dnsdomainname@   id*            nice*          su* doexec*          igawk*         nisdomainname@ sync* [jdoe@frazz jdoe]$ 




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