1.\" Copyright (c) 1980, 1990, 1991, 1993, 1994 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the Institute of Electrical and Electronics Engineers, Inc. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgment: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)ls.1 8.7 (Berkeley) 7/29/94 36.\" $FreeBSD$ 37.\" 38.Dd December 29, 2002 39.Dt LS 1 40.Os 41.Sh NAME 42.Nm ls 43.Nd list directory contents 44.Sh SYNOPSIS 45.Nm 46.Op Fl ABCFGHLPRTWZabcdfghiklnoqrstuw1 47.Op Ar 48.Sh DESCRIPTION 49For each operand that names a 50.Ar file 51of a type other than 52directory, 53.Nm 54displays its name as well as any requested, 55associated information. 56For each operand that names a 57.Ar file 58of type directory, 59.Nm 60displays the names of files contained 61within that directory, as well as any requested, associated 62information. 63.Pp 64If no operands are given, the contents of the current 65directory are displayed. 66If more than one operand is given, 67non-directory operands are displayed first; directory 68and non-directory operands are sorted separately and in 69lexicographical order. 70.Pp 71The following options are available: 72.Bl -tag -width indent 73.It Fl A 74List all entries except for 75.Pa \&. 76and 77.Pa .. . 78Always set for the super-user. 79.It Fl B 80Force printing of non-printable characters (as defined by 81.Xr ctype 3 82and current locale settings) in file names as 83.Li \e Ns Va xxx , 84where 85.Va xxx 86is the numeric value of the character in octal. 87.It Fl C 88Force multi-column output; this is the default when output is to a terminal. 89.It Fl F 90Display a slash 91.Pq Ql / 92immediately after each pathname that is a directory, 93an asterisk 94.Pq Ql * 95after each that is executable, 96an at sign 97.Pq Ql @ 98after each symbolic link, 99an equals sign 100.Pq Ql = 101after each socket, 102a percent sign 103.Pq Ql % 104after each whiteout, 105and a vertical bar 106.Pq Ql \&| 107after each that is a 108.Tn FIFO . 109.It Fl G 110Enable colorized output. 111This option is equivalent to defining 112.Ev CLICOLOR 113in the environment. 114(See below.) 115.It Fl H 116Symbolic links on the command line are followed. 117This option is assumed if 118none of the 119.Fl F , d , 120or 121.Fl l 122options are specified. 123.It Fl L 124If argument is a symbolic link, list the file or directory the link references 125rather than the link itself. 126This option cancels the 127.Fl P 128option. 129.It Fl P 130If argument is a symbolic link, list the link itself rather than the 131object the link references. 132This option cancels the 133.Fl H 134and 135.Fl L 136options. 137.It Fl R 138Recursively list subdirectories encountered. 139.It Fl T 140Display complete time information for the file, including 141month, day, hour, minute, second, and year. 142.It Fl W 143Display whiteouts when scanning directories. 144.It Fl Z 145Display each file's LOMAC level. 146.It Fl a 147Include directory entries whose names begin with a 148dot 149.Pq Pa \&. . 150.It Fl b 151As 152.Fl B , 153but use 154.Tn C 155escape codes whenever possible. 156.It Fl c 157Use time when file status was last changed for sorting or printing. 158.It Fl d 159Directories are listed as plain files (not searched recursively). 160.It Fl f 161Output is not sorted. 162.It Fl g 163This option is deprecated and is only available for compatibility 164with 165.Bx 4.3 ; 166it was used to display the group name in the long 167.Pq Fl l 168format output. 169.It Fl h 170When used wih the 171.Fl l 172option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte 173and Petabyte in order to reduce the number of digits to three or less 174using base 2 for sizes. 175.It Fl i 176For each file, print the file's file serial number (inode number). 177.It Fl k 178If the 179.Fl s 180option is specified, print the file size allocation in kilobytes, 181not blocks. 182This option overrides the environment variable 183.Ev BLOCKSIZE . 184.It Fl l 185(The lowercase letter 186.Dq ell . ) 187List in long format. 188(See below.) 189If the output is to a terminal, a total sum for all the file 190sizes is output on a line before the long listing. 191.It Fl n 192Display user and group IDs numerically rather than converting to a user 193or group name in a long 194.Pq Fl l 195output. 196.It Fl o 197Include the file flags in a long 198.Pq Fl l 199output. 200.It Fl q 201Force printing of non-graphic characters in file names as 202the character 203.Ql \&? ; 204this is the default when output is to a terminal. 205.It Fl r 206Reverse the order of the sort to get reverse 207lexicographical order or the oldest entries first. 208.It Fl s 209Display the number of file system blocks actually used by each file, in units 210of 512 bytes, where partial units are rounded up to the next integer value. 211If the output is to a terminal, a total sum for all the file 212sizes is output on a line before the listing. 213The environment variable 214.Ev BLOCKSIZE 215overrides the unit size of 512 bytes. 216.It Fl t 217Sort by time modified (most recently modified 218first) before sorting the operands by lexicographical 219order. 220.It Fl u 221Use time of last access, 222instead of last modification 223of the file for sorting 224.Pq Fl t 225or printing 226.Pq Fl l . 227.It Fl w 228Force raw printing of non-printable characters. 229This is the default 230when output is not to a terminal. 231.It Fl 1 232(The numeric digit 233.Dq one . ) 234Force output to be 235one entry per line. 236This is the default when 237output is not to a terminal. 238.El 239.Pp 240The 241.Fl 1 , C , 242and 243.Fl l 244options all override each other; the last one specified determines 245the format used. 246.Pp 247The 248.Fl c 249and 250.Fl u 251options override each other; the last one specified determines 252the file time used. 253.Pp 254The 255.Fl B , b , w , 256and 257.Fl q 258options all override each other; the last one specified determines 259the format used for non-printable characters. 260.Pp 261The 262.Fl H , L 263and 264.Fl P 265options all override each other (either partially or fully); they 266are applied in the order specified. 267.Pp 268By default, 269.Nm 270lists one entry per line to standard 271output; the exceptions are to terminals or when the 272.Fl C 273option is specified. 274.Pp 275File information is displayed with one or more 276.Ao blank Ac Ns s 277separating the information associated with the 278.Fl i , s , 279and 280.Fl l 281options. 282.Ss The Long Format 283If the 284.Fl l 285option is given, the following information 286is displayed for each file: 287file mode, 288number of links, owner name, group name, 289LOMAC level, 290number of bytes in the file, abbreviated 291month, day-of-month file was last modified, 292hour file last modified, minute file last 293modified, and the pathname. 294In addition, for each directory whose contents are displayed, the total 295number of 512-byte blocks used by the files in the directory is displayed 296on a line by itself immediately before the information for the files in the 297directory. 298.Pp 299If the modification time of the file is more than 6 months 300in the past or future, then the year of the last modification 301is displayed in place of the hour and minute fields. 302.Pp 303If the owner or group names are not a known user or group name, 304or the 305.Fl n 306option is given, 307the numeric ID's are displayed. 308.Pp 309If the file is a character special or block special file, 310the major and minor device numbers for the file are displayed 311in the size field. 312If the file is a symbolic link the pathname of the 313linked-to file is preceded by 314.Dq Li -> . 315.Pp 316The file mode printed under the 317.Fl l 318option consists of the 319entry type, owner permissions, and group permissions. 320The entry type character describes the type of file, as 321follows: 322.Pp 323.Bl -tag -width 4n -offset indent -compact 324.It Sy b 325Block special file. 326.It Sy c 327Character special file. 328.It Sy d 329Directory. 330.It Sy l 331Symbolic link. 332.It Sy s 333Socket link. 334.It Sy p 335.Tn FIFO . 336.It Sy \- 337Regular file. 338.El 339.Pp 340The next three fields 341are three characters each: 342owner permissions, 343group permissions, and 344other permissions. 345Each field has three character positions: 346.Bl -enum -offset indent 347.It 348If 349.Sy r , 350the file is readable; if 351.Sy \- , 352it is not readable. 353.It 354If 355.Sy w , 356the file is writable; if 357.Sy \- , 358it is not writable. 359.It 360The first of the following that applies: 361.Bl -tag -width 4n -offset indent 362.It Sy S 363If in the owner permissions, the file is not executable and 364set-user-ID mode is set. 365If in the group permissions, the file is not executable 366and set-group-ID mode is set. 367.It Sy s 368If in the owner permissions, the file is executable 369and set-user-ID mode is set. 370If in the group permissions, the file is executable 371and setgroup-ID mode is set. 372.It Sy x 373The file is executable or the directory is 374searchable. 375.It Sy \- 376The file is neither readable, writable, executable, 377nor set-user-ID nor set-group-ID mode, nor sticky. 378(See below.) 379.El 380.Pp 381These next two apply only to the third character in the last group 382(other permissions). 383.Bl -tag -width 4n -offset indent 384.It Sy T 385The sticky bit is set 386(mode 387.Li 1000 ) , 388but not execute or search permission. 389(See 390.Xr chmod 1 391or 392.Xr sticky 8 . ) 393.It Sy t 394The sticky bit is set (mode 395.Li 1000 ) , 396and is searchable or executable. 397(See 398.Xr chmod 1 399or 400.Xr sticky 8 . ) 401.El 402.El 403.Sh EXAMPLES 404The following is how to do an 405.Nm 406listing sorted by size (and shows why 407.Nm 408does not need a separate option for this): 409.Pp 410.Dl "ls -l | sort -n +4" 411.Pp 412Additionally, the 413.Fl r 414flag to 415.Xr sort 1 416may be used 417to get the results sorted from largest to smallest (a reverse sort). 418.Sh DIAGNOSTICS 419.Ex -std 420.Sh ENVIRONMENT 421The following environment variables affect the execution of 422.Nm : 423.Bl -tag -width ".Ev CLICOLOR_FORCE" 424.It Ev BLOCKSIZE 425If the environment variable 426.Ev BLOCKSIZE 427is set, the block counts 428(see 429.Fl s ) 430will be displayed in units of that size block. 431.It Ev CLICOLOR 432Use 433\*[Ai] 434color sequences to distinguish file types. 435See 436.Ev LSCOLORS 437below. 438In addition to the file types mentioned in the 439.Fl F 440option some extra attributes (setuid bit set, etc.) are also displayed. 441The colorization is dependent on a terminal type with the proper 442.Xr termcap 5 443capabilities. 444The default 445.Dq Li cons25 446console has the proper capabilities, 447but to display the colors in an 448.Xr xterm 1 , 449for example, 450the 451.Ev TERM 452variable must be set to 453.Dq Li xterm-color . 454Other terminal types may require similar adjustments. 455Colorization 456is silently disabled if the output isn't directed to a terminal 457unless the 458.Ev CLICOLOR_FORCE 459variable is defined. 460.It Ev CLICOLOR_FORCE 461Color sequences are normally disabled if the output isn't directed to 462a terminal. 463This can be overridden by setting this flag. 464The 465.Ev TERM 466variable still needs to reference a color capable terminal however 467otherwise it is not possible to determine which color sequences to 468use. 469.It Ev COLUMNS 470If this variable contains a string representing a 471decimal integer, it is used as the 472column position width for displaying 473multiple-text-column output. 474The 475.Nm 476utility calculates how 477many pathname text columns to display 478based on the width provided. 479(See 480.Fl C . ) 481.It Ev LANG 482The locale to use when determining the order of day and month in the long 483.Fl l 484format output. 485See 486.Xr environ 7 487for more information. 488.It Ev LSCOLORS 489The value of this variable describes what color to use for which 490attribute when colors are enabled with 491.Ev CLICOLOR . 492This string is a concatenation of pairs of the format 493.Ar f Ns Ar b , 494where 495.Ar f 496is the foreground color and 497.Ar b 498is the background color. 499.Pp 500The color designators are as follows: 501.Pp 502.Bl -tag -width 4n -offset indent -compact 503.It Sy a 504black 505.It Sy b 506red 507.It Sy c 508green 509.It Sy d 510brown 511.It Sy e 512blue 513.It Sy f 514magenta 515.It Sy g 516cyan 517.It Sy h 518light grey 519.It Sy A 520bold black, usually shows up as dark grey 521.It Sy B 522bold red 523.It Sy C 524bold green 525.It Sy D 526bold brown, usually shows up as yellow 527.It Sy E 528bold blue 529.It Sy F 530bold magenta 531.It Sy G 532bold cyan 533.It Sy H 534bold light grey; looks like bright white 535.It Sy x 536default foreground or background 537.El 538.Pp 539Note that the above are standard 540\*[Ai] 541colors. 542The actual display may differ 543depending on the color capabilities of the terminal in use. 544.Pp 545The order of the attributes are as follows: 546.Pp 547.Bl -enum -offset indent -compact 548.It 549directory 550.It 551symbolic link 552.It 553socket 554.It 555pipe 556.It 557executable 558.It 559block special 560.It 561character special 562.It 563executable with setuid bit set 564.It 565executable with setgid bit set 566.It 567directory writable to others, with sticky bit 568.It 569directory writable to others, without sticky bit 570.El 571.Pp 572The default is 573.Qq "exfxcxdxbxegedabagacad" , 574i.e. blue foreground and 575default background for regular directories, black foreground and red 576background for setuid executables, etc. 577.It Ev LS_COLWIDTHS 578If this variable is set, it is considered to be a 579colon-delimited list of minimum column widths. 580Unreasonable 581and insufficient widths are ignored (thus zero signifies 582a dynamically sized column). 583Not all columns have changeable widths. 584The fields are, 585in order: inode, block count, number of links, user name, 586group name, flags, file size, file name. 587.It Ev TERM 588The 589.Ev CLICOLOR 590functionality depends on a terminal type with color capabilities. 591.It Ev TZ 592The timezone to use when displaying dates. 593See 594.Xr environ 7 595for more information. 596.El 597.Sh COMPATIBILITY 598The group field is now automatically included in the long listing for 599files in order to be compatible with the 600.St -p1003.2 601specification. 602.Sh FILES 603.Bl -tag -width ".Pa /dev/lomac" -compact 604.It Pa /dev/lomac 605interface used to query the 606.Xr lomac 4 607KLD 608.El 609.Sh SEE ALSO 610.Xr chflags 1 , 611.Xr chmod 1 , 612.Xr sort 1 , 613.Xr xterm 1 , 614.Xr lomac 4 , 615.Xr termcap 5 , 616.Xr symlink 7 , 617.Xr sticky 8 618.Sh HISTORY 619An 620.Nm 621command appeared in 622.At v1 . 623.Sh STANDARDS 624The 625.Nm 626function is expected to be a superset of the 627.St -p1003.2 628specification. 629.Sh BUGS 630To maintain backward compatibility, the relationships between the many 631options are quite complex. 632