pavement

Ls

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(Using ls with other programs)
m
Line 1: Line 1:
Equivalent to Windows' ''dir''. [[ls]] is commonly used with [[flags]] or [[switches]] to alter it's behaviour and/or output. Flags can be given as seperate 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.
+
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:==
 
==Most common flags:==

Revision as of 17:41, 2 September 2004

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

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 have name in them.

Personal tools