ls (Unix)

from Wikipedia, the free encyclopedia

lsis a by POSIX and the Single UNIX Specification defined command on the command line , in Unix - and Unix-like is implemented systems to the contents of a directory to display. lsis one of the most commonly used Unix commands. lsstands for " l i s t".

history

A ls- utility appeared in the original version of AT & T UNIX . The name is derived from a similar command in Multics .

Today there are different versions of ls. Among other things, there is the version of OpenSolaris , the Free Software Foundation as part of the GNU Coreutils and that of the BSD variants, such as FreeBSD , OpenBSD , NetBSD and Apple's Darwin . All of the above are free software and open source .

function

Unix and Unix-like operating systems have the concept of the working directory , which means nothing else than the current own position in the hierarchy of nested folders . If you now call up lswithout parameters, it shows the content of the working directory. If you also specify any files and / or directories without further parameters, all these files and the contents of these folders will be listed. Usually only the file names are listed without further details (in several columns). The specific behavior is preset and varies in individual systems. An administrator can change the default system-wide, simple users only for themselves.

Options can be used to display further details in the entries in the list. A selection of options:

  • -luses a long list format; shows the Unix file type (whether regular file [-], Directory [d], symbolic link [l], named pipe [p], Block-oriented [b] or character-oriented [c] Device file ), file name and number of hard links , file rights , owner ( user account ), user group , data volume (“size”, “weight”) and date of modification ;
  • -Fappends a character to the file name to characterize it; for example* for a program and /for a directory. No character is appended to regular files;
  • -R also shows the contents of sub-folders recursively;
  • -ado not ignore any file; otherwise files whose names begin with "." (period) are ignored ( hidden files );
  • -d shows information about a directory itself instead of its content, even with a symbolic link to a directory;
  • -t sorts the list by date.

The file format can not spend this program, see file .

In some systems, color output can be activated using an option:

  • --colorin the GNU implementation; to determine the color, the Unix file type, the file rights and the file name extension are taken into account.
  • -Gon FreeBSD and macOS ; the file name extension is not taken into account here.
brw-r--r--    1 unixguy staff 64,  64 Jan 27 05:52 block         
crw-r--r--    1 unixguy staff 64, 255 Jan 26 13:57 character     
-rw-r--r--    1 unixguy staff     290 Jan 26 14:08 compressed.gz 
-rw-r--r--    1 unixguy staff  331836 Jan 26 14:06 data.ppm      
drwxrwx--x    2 unixguy staff      48 Jan 26 11:28 directory     
-rwxrwx--x    1 unixguy staff      29 Jan 26 14:03 executable    
prw-r--r--    1 unixguy staff       0 Jan 26 11:50 fifo          
lrwxrwxrwx    1 unixguy staff       3 Jan 26 11:44 link -> dir   
-rw-rw----    1 unixguy staff     217 Jan 26 14:08 regularfile

On many systems, however, the option for color highlighting does not have to be specified separately, as this is usually already automatically preselected by means of an alias in the configuration of the command line . Further examples of popular aliases are llfor ls -land lfor lsto save typing on these frequently used command variants. In combination with the option -l, the option is often -hgiven to display the file sizes human readable - this means that the file sizes are rounded and displayed with an SI prefix , e.g. 4.2M instead of 4351902 .

Call example

$ ls -l
drwxr--r--   1 fred  editors   4096  drafts
-rw-r--r--   1 fred  editors  30405  edition-32
-r-xr-xr-x   1 fred  fred      8460  edit

The output ( stdout ) contains the following information: user rights , number of hard links , owner, group, size of the file in bytes, file name.

All file information is stored in inodes . The -i parameter is required to display this . The difference between hard links and soft links becomes clear.

Others

lsis also a command in the FTP . In this case, however, the lscommand line program is not called, but a function in the FTP client that sends an LISTor NLSTcommand to the FTP server to request a directory list from the server. See also the Unix command ftp.

Web links