1.\" $NetBSD: ls.1,v 1.57 2005/10/26 02:24:22 jschauma Exp $ 2.\" 3.\" Copyright (c) 1980, 1990, 1991, 1993, 1994 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the Institute of Electrical and Electronics Engineers, Inc. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)ls.1 8.7 (Berkeley) 7/29/94 34.\" 35.Dd October 23, 2005 36.Dt LS 1 37.Os 38.Sh NAME 39.Nm ls 40.Nd list directory contents 41.Sh SYNOPSIS 42.Nm 43.Op Fl AaBbCcdFfghikLlmnopqRrSsTtuWwx1 44.Op Ar 45.Sh DESCRIPTION 46For each operand that names a 47.Ar file 48of a type other than 49directory, 50.Nm 51displays its name as well as any requested, 52associated information. 53For each operand that names a 54.Ar file 55of type directory, 56.Nm 57displays the names of files contained 58within that directory, as well as any requested, associated 59information. 60.Pp 61If no operands are given, the contents of the current 62directory are displayed. 63If more than one operand is given, 64non-directory operands are displayed first; directory 65and non-directory operands are sorted separately and in 66lexicographical order. 67.Pp 68The following options are available: 69.Bl -tag -width indent 70.It Fl A 71List all entries except for 72.Ql \&. 73and 74.Ql \&.. . 75Always set for the super-user. 76.It Fl a 77Include directory entries whose names begin with a 78dot 79.Pq Sq \&. . 80.It Fl B 81Force printing of non-printable characters in file names as \\xxx, where xxx 82is the numeric value of the character in octal. 83.It Fl b 84As 85.Fl B , 86but use C escape codes whenever possible. 87.It Fl C 88Force multi-column output; this is the default when output is to a terminal. 89.It Fl c 90Use time when file status was last changed, 91instead of time of last modification of the file for sorting 92.Pq Fl t 93or printing 94.Pq Fl l . 95.It Fl d 96Directories are listed as plain files (not searched recursively) and 97symbolic links in the argument list are not indirected through. 98.It Fl F 99Display a slash 100.Pq Sq \&/ 101immediately after each pathname that is a directory, 102an asterisk 103.Pq Sq \&* 104after each that is executable, 105an at sign 106.Pq Sq \&@ 107after each symbolic link, 108a percent sign 109.Pq Sq \&% 110after each whiteout, 111an equal sign 112.Pq Sq \&= 113after each socket, 114and a vertical bar 115.Pq Sq \&| 116after each that is a 117.Tn FIFO . 118.It Fl f 119Output is not sorted. 120.It Fl g 121The same as 122.Fl l , 123except that the owner is not printed. 124.It Fl h 125Modifies the 126.Fl s 127and 128.Fl l 129options, causing the sizes to be reported in bytes displayed in a human 130readable format. 131Overrides 132.Fl k . 133.It Fl i 134For each file, print the file's file serial number (inode number). 135.It Fl k 136Modifies the 137.Fl s 138option, causing the sizes to be reported in kilobytes. 139See also 140.Fl h . 141.It Fl L 142For each file, if it's a link, evaluate file information and file type 143of the referenced file and not the link itself; however still print 144the link name, unless used with 145.Fl l , 146for example. 147.It Fl l 148(The lowercase letter 149.Dq ell ) . 150List in long format. 151(See below.) 152A total sum for all the file sizes is output on a line before the long 153listing. 154.It Fl m 155Stream output format; list files across the page, separated by commas. 156.It Fl n 157Display the user and group IDs numerically rather than converting 158to a user or group name in a long 159.Pq Fl l 160output. 161.It Fl o 162Include the file flags in a long 163.Pq Fl l 164output. 165If no file flags are set, 166.Dq - 167is displayed. 168(See 169.Xr chflags 1 170for a list of possible flags and their meanings.) 171.It Fl p 172Display a slash 173.Pq Sq \&/ 174immediately after each pathname that is a directory. 175.It Fl q 176Force printing of non-graphic characters in file names as 177the character 178.Sq \&? ; 179this is the default when output is to a terminal. 180.It Fl R 181Recursively list subdirectories encountered. 182.It Fl r 183Reverse the order of the sort to get reverse 184lexicographical order or the smallest or oldest entries first. 185.It Fl S 186Sort by size, largest file first. 187.It Fl s 188Display the number of file system blocks actually used by each file, in units 189of 512 bytes or 190.Ev BLOCKSIZE 191(see 192.Sx ENVIRONMENT ) 193where partial units are rounded up to the 194next integer value. 195If the output is to a terminal, a total sum for all the file 196sizes is output on a line before the listing. 197.It Fl T 198When used with the 199.Fl l 200(the lowercase letter 201.Dq ell ) 202option, display complete time information for the file, including 203month, day, hour, minute, second, and year. 204.It Fl t 205Sort by time modified (most recently modified 206first) before sorting the operands by lexicographical 207order. 208.It Fl u 209Use time of last access, 210instead of last modification 211of the file for sorting 212.Pq Fl t 213or printing 214.Pq Fl l . 215.It Fl W 216Display whiteouts when scanning directories. 217.It Fl w 218Force raw printing of non-printable characters. 219This is the default when output is not to a terminal. 220.It Fl x 221Multi-column output sorted across the page rather than down the page. 222.It Fl \&1 223(The numeric digit 224.Dq one ) . 225Force output to be one entry per line. 226This is the default when output is not to a terminal. 227.El 228.Pp 229The 230.Fl B , 231.Fl b , 232.Fl w , 233and 234.Fl q 235options all override each other; the last one specified determines 236the format used for non-printable characters. 237.Pp 238The 239.Fl 1 , 240.Fl C , 241.Fl g , 242.Fl l , 243.Fl m , 244and 245.Fl x 246options all override each other; the last one specified determines 247the format used with the exception that if both 248.Fl l 249and 250.Fl g 251are specified, 252.Fl l 253will always override 254.Fl g , 255even if 256.Fl g 257was specified last. 258.Pp 259The 260.Fl c 261and 262.Fl u 263options override each other; the last one specified determines 264the file time used. 265.Pp 266By default, 267.Nm 268lists one entry per line to standard 269output; the exceptions are to terminals or when the 270.Fl C 271or 272.Fl m 273options are specified. 274.Pp 275File information is displayed with one or more 276.Aq blank 277separating the information associated with the 278.Fl i , 279.Fl s , 280and 281.Fl l 282options. 283.Ss The Long Format 284If the 285.Fl l 286option is given, the following information 287is displayed for each file: 288.Bl -item -offset indent -compact 289.It 290file mode 291.It 292number of links 293.It 294owner name 295.It 296group name 297.It 298file flags (if 299.Fl o 300given) 301.It 302number of bytes in the file 303.It 304abbreviated month file was last modified 305.It 306day-of-month file was last modified 307.It 308hour and minute file was last modified 309.It 310pathname 311.El 312.Pp 313In addition, for each directory whose contents are displayed, the total 314number of 512-byte blocks used by the files in the directory is displayed 315on a line by itself immediately before the information for the files in the 316directory. 317.Pp 318If the owner or group names are not a known user or group name, 319or the 320.Fl n 321option is given, 322the numeric ID's are displayed. 323.Pp 324If the file is a character special or block special file, 325the major and minor device numbers for the file are displayed 326in the size field. 327If the file is a symbolic link the pathname of the 328linked-to file is preceded by 329.Dq \-\*[Gt] . 330.Pp 331The file mode printed under the 332.Fl l 333option consists of the entry type, owner permissions, group 334permissions, and other permissions. 335The entry type character describes the type of file, as 336follows: 337.Pp 338.Bl -tag -width 4n -offset indent -compact 339.It Sy b 340Block special file. 341.It Sy c 342Character special file. 343.It Sy d 344Directory. 345.It Sy l 346Symbolic link. 347.It Sy s 348Socket link. 349.It Sy p 350FIFO. 351.It Sy w 352Whiteout. 353.It Sy \- 354Regular file. 355.El 356.Pp 357The next three fields 358are three characters each: 359owner permissions, 360group permissions, and 361other permissions. 362Each field has three character positions: 363.Bl -enum -offset indent 364.It 365If 366.Sy r , 367the file is readable; if 368.Sy \- , 369it is not readable. 370.It 371If 372.Sy w , 373the file is writable; if 374.Sy \- , 375it is not writable. 376.It 377The first of the following that applies: 378.Bl -tag -width 4n -offset indent 379.It Sy S 380If in the owner permissions, the file is not executable and 381set-user-ID mode is set. 382If in the group permissions, the file is not executable 383and set-group-ID mode is set. 384.It Sy s 385If in the owner permissions, the file is executable 386and set-user-ID mode is set. 387If in the group permissions, the file is executable 388and setgroup-ID mode is set. 389.It Sy x 390The file is executable or the directory is 391searchable. 392.It Sy \- 393The file is neither readable, writable, executable, 394nor set-user-ID nor set-group-ID mode, nor sticky. 395(See below.) 396.El 397.Pp 398These next two apply only to the third character in the last group 399(other permissions). 400.Bl -tag -width 4n -offset indent 401.It Sy T 402The sticky bit is set 403(mode 404.Li 1000 ) , 405but not execute or search permission. 406(See 407.Xr chmod 1 408or 409.Xr sticky 8 . ) 410.It Sy t 411The sticky bit is set (mode 412.Li 1000 ) , 413and is searchable or executable. 414(See 415.Xr chmod 1 416or 417.Xr sticky 8 . ) 418.El 419.El 420.Pp 421The number of bytes displayed for a directory is a function of the 422number of 423.Xr dirent 5 424structures in the directory, not all of which may be allocated to 425any existing file. 426.Sh EXIT STATUS 427The 428.Nm 429utility exits 0 on success, and \*[Gt]0 if an error occurs. 430.Sh ENVIRONMENT 431The following environment variables affect the execution of 432.Nm : 433.Bl -tag -width BLOCKSIZE 434.It Ev BLOCKSIZE 435If the environment variable 436.Ev BLOCKSIZE 437is set, and the 438.Fl h 439and 440.Fl k 441options are not specified, the block counts 442(see 443.Fl s ) 444will be displayed in units of that size block. 445.It Ev COLUMNS 446If this variable contains a string representing a 447decimal integer, it is used as the 448column position width for displaying 449multiple-text-column output. 450The 451.Nm 452utility calculates how 453many pathname text columns to display 454based on the width provided. 455(See 456.Fl C . ) 457.It Ev TZ 458The timezone to use when displaying dates. 459See 460.Xr environ 7 461for more information. 462.El 463.Sh COMPATIBILITY 464The group field is now automatically included in the long listing for 465files in order to be compatible with the 466.St -p1003.2 467specification. 468.Sh SEE ALSO 469.Xr chflags 1 , 470.Xr chmod 1 , 471.Xr stat 2 , 472.Xr getbsize 3 , 473.Xr dir 5 , 474.Xr symlink 7 , 475.Xr sticky 8 476.Sh STANDARDS 477The 478.Nm 479utility is expected to be a superset of the 480.St -p1003.2 481specification. 482.Sh HISTORY 483An 484.Nm 485utility appeared in 486.At v5 . 487