pavement

Ls

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (Most common flags:)
m
Line 22: Line 22:
 
and look for all files that begin with '''name'''. But why waste your time going over each entry?
 
and look for all files that begin with '''name'''. But why waste your time going over each entry?
 
  dave@samizdata% '''ls -la | grep name'''
 
  dave@samizdata% '''ls -la | grep name'''
will give you a long list of all files that contain the string '''name'''.
+
will give you a long list of all files that contain the string  
 +
 
 +
==Colorized ls==
 +
If you want a colorized '''ls''' output -- directories in blue, files in green, executables in red, etc -- you'll want to make an alias for ls to '''ls -G''' in your shell configuration file.
 
   
 
   
  
 
[[Category:System Commands]]
 
[[Category:System Commands]]

Revision as of 17:56, 31 July 2005

Equivalent to Windows' dir. ls is commonly used with flags or switches to alter its behaviour and/or output. Flags can be given as separate switches (ls -a -l /etc/) but can be combined to make things faster (ls -la). ls takes pretty much the whole alphabet as a flag, but you'll likely never need or want to use more than say 5 or 6 different flags.

Most common flags:

-a -- lists all files, including hidden files
-l -- gives long listing, including permissions, owner, group and size
-F -- shows a slash (/) immediately after each directory, 
      an asterisk (*) after  executable files, 
      an at sign (@) after symbolic links, 
      an equals sign (=) after sockets, 
      a percent sign (%) after whiteouts, 
      and a pipe (|) after a FIFO.
-R -- list subdirectories encountered recursively
-h -- When used with the -l option, use unit suffixes for sizes so as to make them human-readable. 
      No, Virgina, you do not need to count everything in bytes.
-c -- sort files by the last time file state was changed/modified
-u -- sort files by the last time the file was accessed
-G -- colorize output (different colors for different types of files)

Using ls with other programs

ls can (and is) used in conjunction with grep by using a pipe to send ls output -- which can easily fill your screen with enough entries to make you cross-eyed -- to more easily find what you're looking for. To give an example, let's say you're looking for a file that begins with name in your /etc directory. Doing an ls /etc gives you far too many entries and ls -l the same thing but scrolling past you even faster. You could do a

dave@samizdata% ls | more

and look for all files that begin with name. But why waste your time going over each entry?

dave@samizdata% ls -la | grep name

will give you a long list of all files that contain the string

Colorized ls

If you want a colorized ls output -- directories in blue, files in green, executables in red, etc -- you'll want to make an alias for ls to ls -G in your shell configuration file.

Personal tools