1.\" $NetBSD: ls.1,v 1.65 2010/05/14 17:11:52 joerg 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 September 25, 2008 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-graphic characters in file names as \exxx, 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. 139The rightmost of the 140.Fl k 141and 142.Fl h 143flags overrides the previous flag. 144See also 145.Fl h . 146.It Fl L 147For each file, if it's a link, evaluate file information and file type 148of the referenced file and not the link itself; however still print 149the link name, unless used with 150.Fl l , 151for example. 152.It Fl l 153(The lowercase letter 154.Dq ell ) . 155List in long format. 156(See below.) 157A total sum for all the file sizes is output on a line before the long 158listing. 159.It Fl m 160Stream output format; list files across the page, separated by commas. 161.It Fl n 162The same as 163.Fl l , 164except that 165the owner and group IDs are displayed numerically rather than converting 166to a owner or group name. 167.It Fl o 168Include the file flags in a long 169.Pq Fl l 170output. 171If no file flags are set, 172.Dq - 173is displayed. 174(See 175.Xr chflags 1 176for a list of possible flags and their meanings.) 177.It Fl p 178Display a slash 179.Pq Sq \&/ 180immediately after each pathname that is a directory. 181.It Fl q 182Force printing of non-printable characters in file names as 183the character 184.Sq \&? ; 185this is the default when output is to a terminal. 186.It Fl R 187Recursively list subdirectories encountered. 188.It Fl r 189Reverse the order of the sort to get reverse 190lexicographical order or the smallest or oldest entries first. 191.It Fl S 192Sort by size, largest file first. 193.It Fl s 194Display the number of file system blocks actually used by each file, in units 195of 512 bytes or 196.Ev BLOCKSIZE 197(see 198.Sx ENVIRONMENT ) 199where partial units are rounded up to the 200next integer value. 201If the output is to a terminal, a total sum for all the file 202sizes is output on a line before the listing. 203.It Fl T 204When used with the 205.Fl l 206(the lowercase letter 207.Dq ell ) 208option, display complete time information for the file, including 209month, day, hour, minute, second, and year. 210.It Fl t 211Sort by time modified (most recently modified 212first) before sorting the operands by lexicographical 213order. 214.It Fl u 215Use time of last access, 216instead of last modification 217of the file for sorting 218.Pq Fl t 219or printing 220.Pq Fl l . 221.It Fl W 222Display whiteouts when scanning directories. 223.It Fl w 224Force raw printing of non-printable characters. 225This is the default when output is not to a terminal. 226.It Fl x 227Multi-column output sorted across the page rather than down the page. 228.It Fl \&1 229(The numeric digit 230.Dq one ) . 231Force output to be one entry per line. 232This is the default when output is not to a terminal. 233.El 234.Pp 235The 236.Fl B , 237.Fl b , 238.Fl w , 239and 240.Fl q 241options all override each other; the last one specified determines 242the format used for non-printable characters. 243.Pp 244The 245.Fl 1 , 246.Fl C , 247.Fl g , 248.Fl l , 249.Fl m , 250and 251.Fl x 252options all override each other; the last one specified determines 253the format used with the exception that if both 254.Fl l 255and 256.Fl g 257are specified, 258.Fl l 259will always override 260.Fl g , 261even if 262.Fl g 263was specified last. 264.Pp 265The 266.Fl c 267and 268.Fl u 269options override each other; the last one specified determines 270the file time used. 271.Pp 272By default, 273.Nm 274lists one entry per line to standard 275output; the exceptions are to terminals or when the 276.Fl C 277or 278.Fl m 279options are specified. 280.Pp 281File information is displayed with one or more 282.Aq blank 283separating the information associated with the 284.Fl i , 285.Fl s , 286and 287.Fl l 288options. 289.Ss The Long Format 290If the 291.Fl l 292option is given, the following information 293is displayed for each file: 294.Bl -item -offset indent -compact 295.It 296file mode 297.It 298number of links 299.It 300owner name 301.It 302group name 303.It 304file flags (if 305.Fl o 306given) 307.It 308number of bytes in the file 309.It 310abbreviated month file was last modified 311.It 312day-of-month file was last modified 313.It 314hour and minute file was last modified 315.It 316pathname 317.El 318.Pp 319In addition, for each directory whose contents are displayed, the total 320number of 512-byte blocks used by the files in the directory is displayed 321on a line by itself immediately before the information for the files in the 322directory. 323.Pp 324If the owner or group names are not a known owner or group name, 325or the 326.Fl n 327option is given, 328the numeric ID's are displayed. 329.Pp 330If the file is a character special or block special file, 331the major and minor device numbers for the file are displayed 332in the size field. 333If the file is a symbolic link the pathname of the 334linked-to file is preceded by 335.Dq \-\*[Gt] . 336.Pp 337The file mode printed under the 338.Fl l 339option consists of the entry type, owner permissions, group 340permissions, and other permissions. 341The entry type character describes the type of file, as 342follows: 343.Pp 344.Bl -tag -width 4n -offset indent -compact 345.It Sy a 346Archive state 1. 347.It Sy A 348Archive state 2. 349.It Sy b 350Block special file. 351.It Sy c 352Character special file. 353.It Sy d 354Directory. 355.It Sy l 356Symbolic link. 357.It Sy s 358Socket link. 359.It Sy p 360FIFO. 361.It Sy w 362Whiteout. 363.It Sy \- 364Regular file. 365.El 366.Pp 367The next three fields 368are three characters each: 369owner permissions, 370group permissions, and 371other permissions. 372Each field has three character positions: 373.Bl -enum -offset indent 374.It 375If 376.Sy r , 377the file is readable; if 378.Sy \- , 379it is not readable. 380.It 381If 382.Sy w , 383the file is writable; if 384.Sy \- , 385it is not writable. 386.It 387The first of the following that applies: 388.Bl -tag -width 4n -offset indent 389.It Sy S 390If in the owner permissions, the file is not executable and 391set-user-ID mode is set. 392If in the group permissions, the file is not executable 393and set-group-ID mode is set. 394.It Sy s 395If in the owner permissions, the file is executable 396and set-user-ID mode is set. 397If in the group permissions, the file is executable 398and setgroup-ID mode is set. 399.It Sy x 400The file is executable or the directory is 401searchable. 402.It Sy \- 403The file is neither readable, writable, executable, 404nor set-user-ID nor set-group-ID mode, nor sticky. 405(See below.) 406.El 407.Pp 408These next two apply only to the third character in the last group 409(other permissions). 410.Bl -tag -width 4n -offset indent 411.It Sy T 412The sticky bit is set 413(mode 414.Li 1000 ) , 415but not execute or search permission. 416(See 417.Xr chmod 1 418or 419.Xr sticky 7 . ) 420.It Sy t 421The sticky bit is set (mode 422.Li 1000 ) , 423and is searchable or executable. 424(See 425.Xr chmod 1 426or 427.Xr sticky 7 . ) 428.El 429.El 430.Pp 431The number of bytes displayed for a directory is a function of the 432number of 433.Xr dirent 5 434structures in the directory, not all of which may be allocated to 435any existing file. 436.Sh ENVIRONMENT 437The following environment variables affect the execution of 438.Nm : 439.Bl -tag -width BLOCKSIZE 440.It Ev BLOCKSIZE 441If the environment variable 442.Ev BLOCKSIZE 443is set, and the 444.Fl h 445and 446.Fl k 447options are not specified, the block counts 448(see 449.Fl s ) 450will be displayed in units of that size block. 451.It Ev COLUMNS 452If this variable contains a string representing a 453decimal integer, it is used as the 454column position width for displaying 455multiple-text-column output. 456The 457.Nm 458utility calculates how 459many pathname text columns to display 460based on the width provided. 461(See 462.Fl C . ) 463.It Ev TZ 464The timezone to use when displaying dates. 465See 466.Xr environ 7 467for more information. 468.El 469.Sh EXIT STATUS 470.Ex -std 471.Sh COMPATIBILITY 472The group field is now automatically included in the long listing for 473files in order to be compatible with the 474.St -p1003.2 475specification. 476.Sh SEE ALSO 477.Xr chflags 1 , 478.Xr chmod 1 , 479.Xr stat 2 , 480.Xr getbsize 3 , 481.Xr dir 5 , 482.Xr sticky 7 , 483.Xr symlink 7 484.Sh STANDARDS 485The 486.Nm 487utility is expected to be a superset of the 488.St -p1003.2 489specification. 490.Sh HISTORY 491An 492.Nm 493utility appeared in 494.At v5 . 495