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