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