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 November 16, 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 ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1 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 .. . 75Automatically set for the super-user unless 76.Fl I 77is specified. 78.It Fl B 79Force printing of non-printable characters (as defined by 80.Xr ctype 3 81and current locale settings) in file names as 82.Li \e Ns Va xxx , 83where 84.Va xxx 85is the numeric value of the character in octal. 86.It Fl C 87Force multi-column output; this is the default when output is to a terminal. 88.It Fl F 89Display a slash 90.Pq Ql / 91immediately after each pathname that is a directory, 92an asterisk 93.Pq Ql * 94after each that is executable, 95an at sign 96.Pq Ql @ 97after each symbolic link, 98an equals sign 99.Pq Ql = 100after each socket, 101a percent sign 102.Pq Ql % 103after each whiteout, 104and a vertical bar 105.Pq Ql \&| 106after each that is a 107.Tn FIFO . 108.It Fl G 109Enable colorized output. 110This option is equivalent to defining 111.Ev CLICOLOR 112in the environment. 113(See below.) 114.It Fl H 115Symbolic links on the command line are followed. 116This option is assumed if 117none of the 118.Fl F , d , 119or 120.Fl l 121options are specified. 122.It Fl I 123Prevent 124.Fl A 125from being automatically set for the super-user. 126.It Fl L 127If argument is a symbolic link, list the file or directory the link references 128rather than the link itself. 129This option cancels the 130.Fl P 131option. 132.It Fl P 133If argument is a symbolic link, list the link itself rather than the 134object the link references. 135This option cancels the 136.Fl H 137and 138.Fl L 139options. 140.It Fl R 141Recursively list subdirectories encountered. 142.It Fl S 143Sort by size (largest file first) before sorting the operands in 144lexicographical order. 145.It Fl T 146When used with the 147.Fl l 148(lowercase letter 149.Dq ell ) 150option, display complete time information for the file, including 151month, day, hour, minute, second, and year. 152.It Fl W 153Display whiteouts when scanning directories. 154.It Fl Z 155Display each file's MAC label; see 156.Xr maclabel 7 . 157.It Fl a 158Include directory entries whose names begin with a 159dot 160.Pq Pa \&. . 161.It Fl b 162As 163.Fl B , 164but use 165.Tn C 166escape codes whenever possible. 167.It Fl c 168Use time when file status was last changed for sorting or printing. 169.It Fl d 170Directories are listed as plain files (not searched recursively). 171.It Fl f 172Output is not sorted. 173.It Fl g 174This option is deprecated and is only available for compatibility 175with 176.Bx 4.3 ; 177it was used to display the group name in the long 178.Pq Fl l 179format output. 180.It Fl h 181When used with the 182.Fl l 183option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte 184and Petabyte in order to reduce the number of digits to four or fewer 185using base 2 for sizes. 186.It Fl i 187For each file, print the file's file serial number (inode number). 188.It Fl k 189This has the same effect as setting environment variable 190.Ev BLOCKSIZE 191to 1024, except that it also nullifies any 192.Fl h 193options to its left. 194.It Fl l 195(The lowercase letter 196.Dq ell . ) 197List files in the long format, as described in the 198.Sx The Long Format 199subsection below. 200.It Fl m 201Stream output format; list files across the page, separated by commas. 202.It Fl n 203Display user and group IDs numerically rather than converting to a user 204or group name in a long 205.Pq Fl l 206output. 207.It Fl o 208Include the file flags in a long 209.Pq Fl l 210output. 211.It Fl p 212Write a slash 213.Pq Ql / 214after each filename if that file is a directory. 215.It Fl q 216Force printing of non-graphic characters in file names as 217the character 218.Ql \&? ; 219this is the default when output is to a terminal. 220.It Fl r 221Reverse the order of the sort. 222.It Fl s 223Display the number of blocks used in the file system by each file. 224Block sizes and directory totals are handled as described in 225.Sx The Long Format 226subsection below, except (if the long format is not also requested) 227the directory totals are not output when the output is in a 228single column, even if multi-column output is requested. 229.It Fl t 230Sort by time modified (most recently modified 231first) before sorting the operands in lexicographical 232order. 233.It Fl u 234Use time of last access, 235instead of last modification 236of the file for sorting 237.Pq Fl t 238or printing 239.Pq Fl l . 240.It Fl w 241Force raw printing of non-printable characters. 242This is the default 243when output is not to a terminal. 244.It Fl x 245The same as 246.Fl C , 247except that the multi-column output is produced with entries sorted 248across, rather than down, the columns. 249.It Fl 1 250(The numeric digit 251.Dq one . ) 252Force output to be 253one entry per line. 254This is the default when 255output is not to a terminal. 256.El 257.Pp 258The 259.Fl 1 , C , x , 260and 261.Fl l 262options all override each other; the last one specified determines 263the format used. 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 272The 273.Fl B , b , w , 274and 275.Fl q 276options all override each other; the last one specified determines 277the format used for non-printable characters. 278.Pp 279The 280.Fl H , L 281and 282.Fl P 283options all override each other (either partially or fully); they 284are applied in the order specified. 285.Pp 286By default, 287.Nm 288lists one entry per line to standard 289output; the exceptions are to terminals or when the 290.Fl C 291or 292.Fl x 293options are specified. 294.Pp 295File information is displayed with one or more 296.Ao blank Ac Ns s 297separating the information associated with the 298.Fl i , s , 299and 300.Fl l 301options. 302.Ss The Long Format 303If the 304.Fl l 305option is given, the following information 306is displayed for each file: 307file mode, 308number of links, owner name, group name, 309MAC label, 310number of bytes in the file, abbreviated 311month, day-of-month file was last modified, 312hour file last modified, minute file last 313modified, and the pathname. 314.Pp 315If the modification time of the file is more than 6 months 316in the past or future, then the year of the last modification 317is displayed in place of the hour and minute fields. 318.Pp 319If the owner or group names are not a known user or group name, 320or the 321.Fl n 322option is given, 323the numeric ID's are displayed. 324.Pp 325If the file is a character special or block special file, 326the major and minor device numbers for the file are displayed 327in the size field. 328If the file is a symbolic link the pathname of the 329linked-to file is preceded by 330.Dq Li -> . 331.Pp 332The listing of a directory's contents is preceded 333by a labeled total number of blocks used in the file system by the files 334which are listed as the directory's contents 335(which may or may not include 336.Pa \&. 337and 338.Pa .. 339and other files which start with a dot, depending on other options). 340.Pp 341The default block size is 512 bytes. 342The block size may be set with option 343.Fl k 344or environment variable 345.Ev BLOCKSIZE . 346Numbers of blocks in the output will have been rounded up so the 347numbers of bytes is at least as many as used by the corresponding 348file system blocks (which might have a different size). 349.Pp 350The file mode printed under the 351.Fl l 352option consists of the 353entry type and the permissions. 354The entry type character describes the type of file, as 355follows: 356.Pp 357.Bl -tag -width 4n -offset indent -compact 358.It Sy b 359Block special file. 360.It Sy c 361Character special file. 362.It Sy d 363Directory. 364.It Sy l 365Symbolic link. 366.It Sy s 367Socket link. 368.It Sy p 369.Tn FIFO . 370.It Sy \- 371Regular file. 372.El 373.Pp 374The next three fields 375are three characters each: 376owner permissions, 377group permissions, and 378other permissions. 379Each field has three character positions: 380.Bl -enum -offset indent 381.It 382If 383.Sy r , 384the file is readable; if 385.Sy \- , 386it is not readable. 387.It 388If 389.Sy w , 390the file is writable; if 391.Sy \- , 392it is not writable. 393.It 394The first of the following that applies: 395.Bl -tag -width 4n -offset indent 396.It Sy S 397If in the owner permissions, the file is not executable and 398set-user-ID mode is set. 399If in the group permissions, the file is not executable 400and set-group-ID mode is set. 401.It Sy s 402If in the owner permissions, the file is executable 403and set-user-ID mode is set. 404If in the group permissions, the file is executable 405and setgroup-ID mode is set. 406.It Sy x 407The file is executable or the directory is 408searchable. 409.It Sy \- 410The file is neither readable, writable, executable, 411nor set-user-ID nor set-group-ID mode, nor sticky. 412(See below.) 413.El 414.Pp 415These next two apply only to the third character in the last group 416(other permissions). 417.Bl -tag -width 4n -offset indent 418.It Sy T 419The sticky bit is set 420(mode 421.Li 1000 ) , 422but not execute or search permission. 423(See 424.Xr chmod 1 425or 426.Xr sticky 8 . ) 427.It Sy t 428The sticky bit is set (mode 429.Li 1000 ) , 430and is searchable or executable. 431(See 432.Xr chmod 1 433or 434.Xr sticky 8 . ) 435.El 436.El 437.Pp 438The next field contains a 439plus 440.Pq Ql + 441character if the file has an ACL, or a 442space 443.Pq Ql " " 444if it does not. 445The 446.Nm 447utility does not show the actual ACL; 448use 449.Xr getfacl 1 450to do this. 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 this is set, its value, rounded up to 512 or down to a 457multiple of 512, will be used as the block size in bytes by the 458.Fl l 459and 460.Fl s 461options. 462See 463.Sx The Long Format 464subsection for more information. 465.It Ev CLICOLOR 466Use 467.Tn ANSI 468color sequences to distinguish file types. 469See 470.Ev LSCOLORS 471below. 472In addition to the file types mentioned in the 473.Fl F 474option some extra attributes (setuid bit set, etc.) are also displayed. 475The colorization is dependent on a terminal type with the proper 476.Xr termcap 5 477capabilities. 478The default 479.Dq Li cons25 480console has the proper capabilities, 481but to display the colors in an 482.Xr xterm 1 , 483for example, 484the 485.Ev TERM 486variable must be set to 487.Dq Li xterm-color . 488Other terminal types may require similar adjustments. 489Colorization 490is silently disabled if the output is not directed to a terminal 491unless the 492.Ev CLICOLOR_FORCE 493variable is defined. 494.It Ev CLICOLOR_FORCE 495Color sequences are normally disabled if the output is not directed to 496a terminal. 497This can be overridden by setting this flag. 498The 499.Ev TERM 500variable still needs to reference a color capable terminal however 501otherwise it is not possible to determine which color sequences to 502use. 503.It Ev COLUMNS 504If this variable contains a string representing a 505decimal integer, it is used as the 506column position width for displaying 507multiple-text-column output. 508The 509.Nm 510utility calculates how 511many pathname text columns to display 512based on the width provided. 513(See 514.Fl C 515and 516.Fl x . ) 517.It Ev LANG 518The locale to use when determining the order of day and month in the long 519.Fl l 520format output. 521See 522.Xr environ 7 523for more information. 524.It Ev LSCOLORS 525The value of this variable describes what color to use for which 526attribute when colors are enabled with 527.Ev CLICOLOR . 528This string is a concatenation of pairs of the format 529.Ar f Ns Ar b , 530where 531.Ar f 532is the foreground color and 533.Ar b 534is the background color. 535.Pp 536The color designators are as follows: 537.Pp 538.Bl -tag -width 4n -offset indent -compact 539.It Sy a 540black 541.It Sy b 542red 543.It Sy c 544green 545.It Sy d 546brown 547.It Sy e 548blue 549.It Sy f 550magenta 551.It Sy g 552cyan 553.It Sy h 554light grey 555.It Sy A 556bold black, usually shows up as dark grey 557.It Sy B 558bold red 559.It Sy C 560bold green 561.It Sy D 562bold brown, usually shows up as yellow 563.It Sy E 564bold blue 565.It Sy F 566bold magenta 567.It Sy G 568bold cyan 569.It Sy H 570bold light grey; looks like bright white 571.It Sy x 572default foreground or background 573.El 574.Pp 575Note that the above are standard 576.Tn ANSI 577colors. 578The actual display may differ 579depending on the color capabilities of the terminal in use. 580.Pp 581The order of the attributes are as follows: 582.Pp 583.Bl -enum -offset indent -compact 584.It 585directory 586.It 587symbolic link 588.It 589socket 590.It 591pipe 592.It 593executable 594.It 595block special 596.It 597character special 598.It 599executable with setuid bit set 600.It 601executable with setgid bit set 602.It 603directory writable to others, with sticky bit 604.It 605directory writable to others, without sticky bit 606.El 607.Pp 608The default is 609.Qq "exfxcxdxbxegedabagacad" , 610i.e., blue foreground and 611default background for regular directories, black foreground and red 612background for setuid executables, etc. 613.It Ev LS_COLWIDTHS 614If this variable is set, it is considered to be a 615colon-delimited list of minimum column widths. 616Unreasonable 617and insufficient widths are ignored (thus zero signifies 618a dynamically sized column). 619Not all columns have changeable widths. 620The fields are, 621in order: inode, block count, number of links, user name, 622group name, flags, file size, file name. 623.It Ev TERM 624The 625.Ev CLICOLOR 626functionality depends on a terminal type with color capabilities. 627.It Ev TZ 628The timezone to use when displaying dates. 629See 630.Xr environ 7 631for more information. 632.El 633.Sh EXIT STATUS 634.Ex -std 635.Sh COMPATIBILITY 636The group field is now automatically included in the long listing for 637files in order to be compatible with the 638.St -p1003.2 639specification. 640.Sh SEE ALSO 641.Xr chflags 1 , 642.Xr chmod 1 , 643.Xr getfacl 1 , 644.Xr sort 1 , 645.Xr xterm 1 , 646.Xr termcap 5 , 647.Xr maclabel 7 , 648.Xr symlink 7 , 649.Xr getfmac 8 , 650.Xr sticky 8 651.Sh STANDARDS 652With the exception of options 653.Fl I , g , n 654and 655.Fl o , 656the 657.Nm 658utility conforms to 659.St -p1003.1-2001 . 660.Pp 661The ACL support is compatible with 662.Tn IEEE 663Std\~1003.2c 664.Pq Dq Tn POSIX Ns .2c 665Draft\~17 666(withdrawn). 667.Sh HISTORY 668An 669.Nm 670command appeared in 671.At v1 . 672.Sh BUGS 673To maintain backward compatibility, the relationships between the many 674options are quite complex. 675.Pp 676The exception mentioned in the 677.Fl s 678option description might be a feature that was 679based on the fact that single-column output 680usually goes to something other than a terminal. 681It is debatable whether this is a design bug. 682