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 May 19, 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 ABCFGHLPRTWZabcdfghiklmnopqrstuwx1 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 140When used with the 141.Fl l 142(lowercase letter 143.Dq ell ) 144option, display complete time information for the file, including 145month, day, hour, minute, second, and year. 146.It Fl W 147Display whiteouts when scanning directories. 148.It Fl Z 149Display each file's MAC label. 150.It Fl a 151Include directory entries whose names begin with a 152dot 153.Pq Pa \&. . 154.It Fl b 155As 156.Fl B , 157but use 158.Tn C 159escape codes whenever possible. 160.It Fl c 161Use time when file status was last changed for sorting or printing. 162.It Fl d 163Directories are listed as plain files (not searched recursively). 164.It Fl f 165Output is not sorted. 166.It Fl g 167This option is deprecated and is only available for compatibility 168with 169.Bx 4.3 ; 170it was used to display the group name in the long 171.Pq Fl l 172format output. 173.It Fl h 174When used with the 175.Fl l 176option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte 177and Petabyte in order to reduce the number of digits to three or less 178using base 2 for sizes. 179.It Fl i 180For each file, print the file's file serial number (inode number). 181.It Fl k 182If the 183.Fl s 184option is specified, print the file size allocation in kilobytes, 185not blocks. 186This option overrides the environment variable 187.Ev BLOCKSIZE . 188.It Fl l 189(The lowercase letter 190.Dq ell . ) 191List in long format. 192(See below.) 193If the output is to a terminal, a total sum for all the file 194sizes is output on a line before the long listing. 195.It Fl m 196Stream output format; list files across the page, separated by commas. 197.It Fl n 198Display user and group IDs numerically rather than converting to a user 199or group name in a long 200.Pq Fl l 201output. 202.It Fl o 203Include the file flags in a long 204.Pq Fl l 205output. 206.It Fl p 207Write a slash 208.Pq Ql / 209after each filename if that file is a directory. 210.It Fl q 211Force printing of non-graphic characters in file names as 212the character 213.Ql \&? ; 214this is the default when output is to a terminal. 215.It Fl r 216Reverse the order of the sort to get reverse 217lexicographical order or the oldest entries first. 218.It Fl s 219Display the number of file system blocks actually used by each file, in units 220of 512 bytes, where partial units are rounded up to the next integer value. 221If the output is to a terminal, a total sum for all the file 222sizes is output on a line before the listing. 223The environment variable 224.Ev BLOCKSIZE 225overrides the unit size of 512 bytes. 226.It Fl t 227Sort by time modified (most recently modified 228first) before sorting the operands by lexicographical 229order. 230.It Fl u 231Use time of last access, 232instead of last modification 233of the file for sorting 234.Pq Fl t 235or printing 236.Pq Fl l . 237.It Fl w 238Force raw printing of non-printable characters. 239This is the default 240when output is not to a terminal. 241.It Fl x 242The same as 243.Fl C , 244except that the multi-column output is produced with entries sorted 245across, rather than down, the columns. 246.It Fl 1 247(The numeric digit 248.Dq one . ) 249Force output to be 250one entry per line. 251This is the default when 252output is not to a terminal. 253.El 254.Pp 255The 256.Fl 1 , C , x , 257and 258.Fl l 259options all override each other; the last one specified determines 260the format used. 261.Pp 262The 263.Fl c 264and 265.Fl u 266options override each other; the last one specified determines 267the file time used. 268.Pp 269The 270.Fl B , b , w , 271and 272.Fl q 273options all override each other; the last one specified determines 274the format used for non-printable characters. 275.Pp 276The 277.Fl H , L 278and 279.Fl P 280options all override each other (either partially or fully); they 281are applied in the order specified. 282.Pp 283By default, 284.Nm 285lists one entry per line to standard 286output; the exceptions are to terminals or when the 287.Fl C 288or 289.Fl x 290options are specified. 291.Pp 292File information is displayed with one or more 293.Ao blank Ac Ns s 294separating the information associated with the 295.Fl i , s , 296and 297.Fl l 298options. 299.Ss The Long Format 300If the 301.Fl l 302option is given, the following information 303is displayed for each file: 304file mode, 305number of links, owner name, group name, 306MAC label, 307number of bytes in the file, abbreviated 308month, day-of-month file was last modified, 309hour file last modified, minute file last 310modified, and the pathname. 311In addition, for each directory whose contents are displayed, the total 312number of 512-byte blocks used by the files in the directory is displayed 313on a line by itself immediately before the information for the files in the 314directory. 315.Pp 316If the modification time of the file is more than 6 months 317in the past or future, then the year of the last modification 318is displayed in place of the hour and minute fields. 319.Pp 320If the owner or group names are not a known user or group name, 321or the 322.Fl n 323option is given, 324the numeric ID's are displayed. 325.Pp 326If the file is a character special or block special file, 327the major and minor device numbers for the file are displayed 328in the size field. 329If the file is a symbolic link the pathname of the 330linked-to file is preceded by 331.Dq Li -> . 332.Pp 333The file mode printed under the 334.Fl l 335option consists of the 336entry type, owner permissions, and group permissions. 337The entry type character describes the type of file, as 338follows: 339.Pp 340.Bl -tag -width 4n -offset indent -compact 341.It Sy b 342Block special file. 343.It Sy c 344Character special file. 345.It Sy d 346Directory. 347.It Sy l 348Symbolic link. 349.It Sy s 350Socket link. 351.It Sy p 352.Tn FIFO . 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 next field contains a 422plus 423.Pq Ql + 424character if the file has an ACL, or a 425space 426.Pq Ql " " 427if it does not. 428The 429.Nm 430utility does not show the actual ACL; 431use 432.Xr getfacl 1 433to do this. 434.Sh EXAMPLES 435The following is how to do an 436.Nm 437listing sorted by size (and shows why 438.Nm 439does not need a separate option for this): 440.Pp 441.Dl "ls -l | sort -n +4" 442.Pp 443Additionally, the 444.Fl r 445flag to 446.Xr sort 1 447may be used 448to get the results sorted from largest to smallest (a reverse sort). 449.Sh DIAGNOSTICS 450.Ex -std 451.Sh ENVIRONMENT 452The following environment variables affect the execution of 453.Nm : 454.Bl -tag -width ".Ev CLICOLOR_FORCE" 455.It Ev BLOCKSIZE 456If the environment variable 457.Ev BLOCKSIZE 458is set, the block counts 459(see 460.Fl s ) 461will be displayed in units of that size block. 462.It Ev CLICOLOR 463Use 464.Tn ANSI 465color sequences to distinguish file types. 466See 467.Ev LSCOLORS 468below. 469In addition to the file types mentioned in the 470.Fl F 471option some extra attributes (setuid bit set, etc.) are also displayed. 472The colorization is dependent on a terminal type with the proper 473.Xr termcap 5 474capabilities. 475The default 476.Dq Li cons25 477console has the proper capabilities, 478but to display the colors in an 479.Xr xterm 1 , 480for example, 481the 482.Ev TERM 483variable must be set to 484.Dq Li xterm-color . 485Other terminal types may require similar adjustments. 486Colorization 487is silently disabled if the output isn't directed to a terminal 488unless the 489.Ev CLICOLOR_FORCE 490variable is defined. 491.It Ev CLICOLOR_FORCE 492Color sequences are normally disabled if the output isn't directed to 493a terminal. 494This can be overridden by setting this flag. 495The 496.Ev TERM 497variable still needs to reference a color capable terminal however 498otherwise it is not possible to determine which color sequences to 499use. 500.It Ev COLUMNS 501If this variable contains a string representing a 502decimal integer, it is used as the 503column position width for displaying 504multiple-text-column output. 505The 506.Nm 507utility calculates how 508many pathname text columns to display 509based on the width provided. 510(See 511.Fl C 512and 513.Fl x . ) 514.It Ev LANG 515The locale to use when determining the order of day and month in the long 516.Fl l 517format output. 518See 519.Xr environ 7 520for more information. 521.It Ev LSCOLORS 522The value of this variable describes what color to use for which 523attribute when colors are enabled with 524.Ev CLICOLOR . 525This string is a concatenation of pairs of the format 526.Ar f Ns Ar b , 527where 528.Ar f 529is the foreground color and 530.Ar b 531is the background color. 532.Pp 533The color designators are as follows: 534.Pp 535.Bl -tag -width 4n -offset indent -compact 536.It Sy a 537black 538.It Sy b 539red 540.It Sy c 541green 542.It Sy d 543brown 544.It Sy e 545blue 546.It Sy f 547magenta 548.It Sy g 549cyan 550.It Sy h 551light grey 552.It Sy A 553bold black, usually shows up as dark grey 554.It Sy B 555bold red 556.It Sy C 557bold green 558.It Sy D 559bold brown, usually shows up as yellow 560.It Sy E 561bold blue 562.It Sy F 563bold magenta 564.It Sy G 565bold cyan 566.It Sy H 567bold light grey; looks like bright white 568.It Sy x 569default foreground or background 570.El 571.Pp 572Note that the above are standard 573.Tn ANSI 574colors. 575The actual display may differ 576depending on the color capabilities of the terminal in use. 577.Pp 578The order of the attributes are as follows: 579.Pp 580.Bl -enum -offset indent -compact 581.It 582directory 583.It 584symbolic link 585.It 586socket 587.It 588pipe 589.It 590executable 591.It 592block special 593.It 594character special 595.It 596executable with setuid bit set 597.It 598executable with setgid bit set 599.It 600directory writable to others, with sticky bit 601.It 602directory writable to others, without sticky bit 603.El 604.Pp 605The default is 606.Qq "exfxcxdxbxegedabagacad" , 607i.e. blue foreground and 608default background for regular directories, black foreground and red 609background for setuid executables, etc. 610.It Ev LS_COLWIDTHS 611If this variable is set, it is considered to be a 612colon-delimited list of minimum column widths. 613Unreasonable 614and insufficient widths are ignored (thus zero signifies 615a dynamically sized column). 616Not all columns have changeable widths. 617The fields are, 618in order: inode, block count, number of links, user name, 619group name, flags, file size, file name. 620.It Ev TERM 621The 622.Ev CLICOLOR 623functionality depends on a terminal type with color capabilities. 624.It Ev TZ 625The timezone to use when displaying dates. 626See 627.Xr environ 7 628for more information. 629.El 630.Sh COMPATIBILITY 631The group field is now automatically included in the long listing for 632files in order to be compatible with the 633.St -p1003.2 634specification. 635.Sh SEE ALSO 636.Xr chflags 1 , 637.Xr chmod 1 , 638.Xr getfacl 1 , 639.Xr sort 1 , 640.Xr xterm 1 , 641.Xr termcap 5 , 642.Xr symlink 7 , 643.Xr getfmac 8 , 644.Xr sticky 8 645.Sh STANDARDS 646The 647.Nm 648utility conforms to 649.St -p1003.1-2001 . 650.Pp 651The ACL support is compatible with 652.Tn IEEE 653Std\~1003.2c 654.Pq Dq Tn POSIX Ns .2c 655Draft\~17 656(withdrawn). 657.Sh HISTORY 658An 659.Nm 660command appeared in 661.At v1 . 662.Sh BUGS 663To maintain backward compatibility, the relationships between the many 664options are quite complex. 665