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