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