O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  

know 'ls'
Get to know what [ls] can do with its hidden features..

Contributed by:
Dawa Lama
[01/23/04 | Discuss (5) | Link to this hack]

ls explored

Generally ls is used just for listing the entries in a directory. But there is more to ls. If you look up the man page for 'ls' or 'info ls', then you can begin to understand the varieties of things 'ls' is capable of. 

Let's work through few of the things you can do with ls. 
  • Show all the files including [.] files:
    ls -a
  • Sort by last modified date:
    ls -t
  • Show detailed info (permission, owner, date etc):
    ls -l
  • Show filesize in KB or MB instead of bytes:
    ls -lh
  • Show files starting with character a only:
    ls a*
  • Show files without 'a' as the first letter:
    ls [^a]*
    Note the above command will list all the files recursively if there are directories in the current path.
    ls -d [^a]*
    -d will restrict the display to the base directory
    Multiple excludes
    ls -d [^abc]* will display all the files except those starting with a b and c.
  • More information can be found if you look into 'info ls'

  • O'Reilly Home | Privacy Policy

    © 2007 O'Reilly Media, Inc.
    Website: | Customer Service: | Book issues:

    All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.