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.\" 3. 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 August 18, 2018 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 ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1, 44.Op Fl -color Ns = Ns Ar when 45.Op Fl D Ar format 46.Op Ar 47.Sh DESCRIPTION 48For each operand that names a 49.Ar file 50of a type other than 51directory, 52.Nm 53displays its name as well as any requested, 54associated information. 55For each operand that names a 56.Ar file 57of type directory, 58.Nm 59displays the names of files contained 60within that directory, as well as any requested, associated 61information. 62.Pp 63If no operands are given, the contents of the current 64directory are displayed. 65If more than one operand is given, 66non-directory operands are displayed first; directory 67and non-directory operands are sorted separately and in 68lexicographical order. 69.Pp 70The following options are available: 71.Bl -tag -width indent 72.It Fl A 73Include directory entries whose names begin with a 74dot 75.Pq Sq Pa \&. 76except for 77.Pa \&. 78and 79.Pa .. . 80Automatically set for the super-user unless 81.Fl I 82is specified. 83.It Fl B 84Force printing of non-printable characters (as defined by 85.Xr ctype 3 86and current locale settings) in file names as 87.Li \e Ns Va xxx , 88where 89.Va xxx 90is the numeric value of the character in octal. 91This option is not defined in 92.St -p1003.1-2001 . 93.It Fl C 94Force multi-column output; this is the default when output is to a terminal. 95.It Fl D Ar format 96When printing in the long 97.Pq Fl l 98format, use 99.Ar format 100to format the date and time output. 101The argument 102.Ar format 103is a string used by 104.Xr strftime 3 . 105Depending on the choice of format string, this may result in a 106different number of columns in the output. 107This option overrides the 108.Fl T 109option. 110This option is not defined in 111.St -p1003.1-2001 . 112.It Fl F 113Display a slash 114.Pq Ql / 115immediately after each pathname that is a directory, 116an asterisk 117.Pq Ql * 118after each that is executable, 119an at sign 120.Pq Ql @ 121after each symbolic link, 122an equals sign 123.Pq Ql = 124after each socket, 125a percent sign 126.Pq Ql % 127after each whiteout, 128and a vertical bar 129.Pq Ql \&| 130after each that is a 131.Tn FIFO . 132.It Fl G 133Enable colorized output. 134This option is equivalent to defining 135.Ev CLICOLOR 136or 137.Ev COLORTERM 138in the environment. 139(See below.) 140This functionality can be compiled out by removing the definition of 141.Ev COLORLS . 142This option is not defined in 143.St -p1003.1-2001 . 144.It Fl H 145Symbolic links on the command line are followed. 146This option is assumed if 147none of the 148.Fl F , d , 149or 150.Fl l 151options are specified. 152.It Fl I 153Prevent 154.Fl A 155from being automatically set for the super-user. 156This option is not defined in 157.St -p1003.1-2001 . 158.It Fl L 159If argument is a symbolic link, list the file or directory the link references 160rather than the link itself. 161This option cancels the 162.Fl P 163option. 164.It Fl P 165If argument is a symbolic link, list the link itself rather than the 166object the link references. 167This option cancels the 168.Fl H 169and 170.Fl L 171options. 172.It Fl R 173Recursively list subdirectories encountered. 174.It Fl S 175Sort by size (largest file first) before sorting the operands in 176lexicographical order. 177.It Fl T 178When printing in the long 179.Pq Fl l 180format, display complete time information for the file, including 181month, day, hour, minute, second, and year. 182The 183.Fl D 184option gives even more control over the output format. 185This option is not defined in 186.St -p1003.1-2001 . 187.It Fl U 188Use time when file was created for sorting or printing. 189This option is not defined in 190.St -p1003.1-2001 . 191.It Fl W 192Display whiteouts when scanning directories. 193This option is not defined in 194.St -p1003.1-2001 . 195.It Fl Z 196Display each file's MAC label; see 197.Xr maclabel 7 . 198This option is not defined in 199.St -p1003.1-2001 . 200.It Fl a 201Include directory entries whose names begin with a 202dot 203.Pq Sq Pa \&. . 204.It Fl b 205As 206.Fl B , 207but use 208.Tn C 209escape codes whenever possible. 210This option is not defined in 211.St -p1003.1-2001 . 212.It Fl c 213Use time when file status was last changed for sorting or printing. 214.It Fl -color Ns = Ns Ar when 215Output colored escape sequences based on 216.Ar when , 217which may be set to either 218.Cm always , 219.Cm auto 220(default), or 221.Cm never . 222.Pp 223.Cm always 224will make 225.Nm 226always output color. 227If 228.Ev TERM 229is unset or set to an invalid terminal, then 230.Nm 231will fall back to explicit 232.Tn ANSI 233escape sequences without the help of 234.Xr termcap 5 . 235.Cm always 236is the default if 237.Fl -color 238is specified without an argument. 239.Pp 240.Cm auto 241will make 242.Nm 243output escape sequences based on 244.Xr termcap 5 , 245but only if 246.Dv stdout 247is a tty and either the 248.Fl G 249flag is specified or the 250.Ev COLORTERM 251environment variable is set and not empty. 252.Pp 253.Cm never 254will disable color regardless of environment variables. 255.Pp 256For compatibility with GNU coreutils, 257.Nm 258supports 259.Cm yes 260or 261.Cm force 262as equivalent to 263.Cm always , 264.Cm no 265or 266.Cm none 267as equivalent to 268.Cm never , 269and 270.Cm tty 271or 272.Cm if-tty 273as equivalent to 274.Cm auto . 275.It Fl d 276Directories are listed as plain files (not searched recursively). 277.It Fl f 278Output is not sorted. 279This option turns on 280.Fl a . 281It also negates the effect of the 282.Fl r , 283.Fl S 284and 285.Fl t 286options. 287As allowed by 288.St -p1003.1-2001 , 289this option has no effect on the 290.Fl d , 291.Fl l , 292.Fl R 293and 294.Fl s 295options. 296.It Fl g 297This option has no effect. 298It is only available for compatibility with 299.Bx 4.3 , 300where it was used to display the group name in the long 301.Pq Fl l 302format output. 303This option is incompatible with 304.St -p1003.1-2001 . 305.It Fl h 306When used with the 307.Fl l 308option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte 309and Petabyte in order to reduce the number of digits to four or fewer 310using base 2 for sizes. 311This option is not defined in 312.St -p1003.1-2001 . 313.It Fl i 314For each file, print the file's file serial number (inode number). 315.It Fl k 316This has the same effect as setting environment variable 317.Ev BLOCKSIZE 318to 1024, except that it also nullifies any 319.Fl h 320options to its left. 321.It Fl l 322(The lowercase letter 323.Dq ell . ) 324List files in the long format, as described in the 325.Sx The Long Format 326subsection below. 327.It Fl m 328Stream output format; list files across the page, separated by commas. 329.It Fl n 330Display user and group IDs numerically rather than converting to a user 331or group name in a long 332.Pq Fl l 333output. 334.It Fl o 335Include the file flags in a long 336.Pq Fl l 337output. 338This option is incompatible with 339.St -p1003.1-2001 . 340See 341.Xr chflags 1 342for a list of file flags and their meanings. 343.It Fl p 344Write a slash 345.Pq Ql / 346after each filename if that file is a directory. 347.It Fl q 348Force printing of non-graphic characters in file names as 349the character 350.Ql \&? ; 351this is the default when output is to a terminal. 352.It Fl r 353Reverse the order of the sort. 354.It Fl s 355Display the number of blocks used in the file system by each file. 356Block sizes and directory totals are handled as described in 357.Sx The Long Format 358subsection below, except (if the long format is not also requested) 359the directory totals are not output when the output is in a 360single column, even if multi-column output is requested. 361.It Fl t 362Sort by descending time modified (most recently modified first). 363If two files have the same modification timestamp, sort their names 364in ascending lexicographical order. 365The 366.Fl r 367option reverses both of these sort orders. 368.Pp 369Note that these sort orders are contradictory: the time sequence is in 370descending order, the lexicographical sort is in ascending order. 371This behavior is mandated by 372.St -p1003.2 . 373This feature can cause problems listing files stored with sequential names on 374FAT file systems, such as from digital cameras, where it is possible to have 375more than one image with the same timestamp. 376In such a case, the photos cannot be listed in the sequence in which 377they were taken. 378To ensure the same sort order for time and for lexicographical sorting, set the 379environment variable 380.Ev LS_SAMESORT 381or use the 382.Fl y 383option. 384This causes 385.Nm 386to reverse the lexicographical sort order when sorting files with the 387same modification timestamp. 388.It Fl u 389Use time of last access, 390instead of time of last modification 391of the file for sorting 392.Pq Fl t 393or printing 394.Pq Fl l . 395.It Fl w 396Force raw printing of non-printable characters. 397This is the default 398when output is not to a terminal. 399This option is not defined in 400.St -p1003.1-2001 . 401.It Fl x 402The same as 403.Fl C , 404except that the multi-column output is produced with entries sorted 405across, rather than down, the columns. 406.It Fl y 407When the 408.Fl t 409option is set, sort the alphabetical output in the same order as the time output. 410This has the same effect as setting 411.Ev LS_SAMESORT . 412See the description of the 413.Fl t 414option for more details. 415This option is not defined in 416.St -p1003.1-2001 . 417.It Fl 1 418(The numeric digit 419.Dq one . ) 420Force output to be 421one entry per line. 422This is the default when 423output is not to a terminal. 424.It Fl , 425(Comma) When the 426.Fl l 427option is set, print file sizes grouped and separated by thousands using the 428non-monetary separator returned by 429.Xr localeconv 3 , 430typically a comma or period. 431If no locale is set, or the locale does not have a non-monetary separator, this 432option has no effect. 433This option is not defined in 434.St -p1003.1-2001 . 435.El 436.Pp 437The 438.Fl 1 , C , x , 439and 440.Fl l 441options all override each other; the last one specified determines 442the format used. 443.Pp 444The 445.Fl c , u , 446and 447.Fl U 448options all override each other; the last one specified determines 449the file time used. 450.Pp 451The 452.Fl S 453and 454.Fl t 455options override each other; the last one specified determines 456the sort order used. 457.Pp 458The 459.Fl B , b , w , 460and 461.Fl q 462options all override each other; the last one specified determines 463the format used for non-printable characters. 464.Pp 465The 466.Fl H , L 467and 468.Fl P 469options all override each other (either partially or fully); they 470are applied in the order specified. 471.Pp 472By default, 473.Nm 474lists one entry per line to standard 475output; the exceptions are to terminals or when the 476.Fl C 477or 478.Fl x 479options are specified. 480.Pp 481File information is displayed with one or more 482.Ao blank Ac Ns s 483separating the information associated with the 484.Fl i , s , 485and 486.Fl l 487options. 488.Ss The Long Format 489If the 490.Fl l 491option is given, the following information 492is displayed for each file: 493file mode, 494number of links, owner name, group name, 495MAC label, 496number of bytes in the file, abbreviated 497month, day-of-month file was last modified, 498hour file last modified, minute file last 499modified, and the pathname. 500.Pp 501If the modification time of the file is more than 6 months 502in the past or future, and the 503.Fl D 504or 505.Fl T 506are not specified, 507then the year of the last modification 508is displayed in place of the hour and minute fields. 509.Pp 510If the owner or group names are not a known user or group name, 511or the 512.Fl n 513option is given, 514the numeric ID's are displayed. 515.Pp 516If the file is a character special or block special file, 517the device number for the file is displayed in the size field. 518If the file is a symbolic link the pathname of the 519linked-to file is preceded by 520.Dq Li -> . 521.Pp 522The listing of a directory's contents is preceded 523by a labeled total number of blocks used in the file system by the files 524which are listed as the directory's contents 525(which may or may not include 526.Pa \&. 527and 528.Pa .. 529and other files which start with a dot, depending on other options). 530.Pp 531The default block size is 512 bytes. 532The block size may be set with option 533.Fl k 534or environment variable 535.Ev BLOCKSIZE . 536Numbers of blocks in the output will have been rounded up so the 537numbers of bytes is at least as many as used by the corresponding 538file system blocks (which might have a different size). 539.Pp 540The file mode printed under the 541.Fl l 542option consists of the 543entry type and the permissions. 544The entry type character describes the type of file, as 545follows: 546.Pp 547.Bl -tag -width 4n -offset indent -compact 548.It Sy \- 549Regular file. 550.It Sy b 551Block special file. 552.It Sy c 553Character special file. 554.It Sy d 555Directory. 556.It Sy l 557Symbolic link. 558.It Sy p 559.Tn FIFO . 560.It Sy s 561Socket. 562.It Sy w 563Whiteout. 564.El 565.Pp 566The next three fields 567are three characters each: 568owner permissions, 569group permissions, and 570other permissions. 571Each field has three character positions: 572.Bl -enum -offset indent 573.It 574If 575.Sy r , 576the file is readable; if 577.Sy \- , 578it is not readable. 579.It 580If 581.Sy w , 582the file is writable; if 583.Sy \- , 584it is not writable. 585.It 586The first of the following that applies: 587.Bl -tag -width 4n -offset indent 588.It Sy S 589If in the owner permissions, the file is not executable and 590set-user-ID mode is set. 591If in the group permissions, the file is not executable 592and set-group-ID mode is set. 593.It Sy s 594If in the owner permissions, the file is executable 595and set-user-ID mode is set. 596If in the group permissions, the file is executable 597and setgroup-ID mode is set. 598.It Sy x 599The file is executable or the directory is 600searchable. 601.It Sy \- 602The file is neither readable, writable, executable, 603nor set-user-ID nor set-group-ID mode, nor sticky. 604(See below.) 605.El 606.Pp 607These next two apply only to the third character in the last group 608(other permissions). 609.Bl -tag -width 4n -offset indent 610.It Sy T 611The sticky bit is set 612(mode 613.Li 1000 ) , 614but not execute or search permission. 615(See 616.Xr chmod 1 617or 618.Xr sticky 7 . ) 619.It Sy t 620The sticky bit is set (mode 621.Li 1000 ) , 622and is searchable or executable. 623(See 624.Xr chmod 1 625or 626.Xr sticky 7 . ) 627.El 628.El 629.Pp 630The next field contains a 631plus 632.Pq Ql + 633character if the file has an ACL, or a 634space 635.Pq Ql " " 636if it does not. 637The 638.Nm 639utility does not show the actual ACL; 640use 641.Xr getfacl 1 642to do this. 643.Sh ENVIRONMENT 644The following environment variables affect the execution of 645.Nm : 646.Bl -tag -width ".Ev CLICOLOR_FORCE" 647.It Ev BLOCKSIZE 648If this is set, its value, rounded up to 512 or down to a 649multiple of 512, will be used as the block size in bytes by the 650.Fl l 651and 652.Fl s 653options. 654See 655.Sx The Long Format 656subsection for more information. 657.It Ev CLICOLOR 658Use 659.Tn ANSI 660color sequences to distinguish file types. 661See 662.Ev LSCOLORS 663below. 664In addition to the file types mentioned in the 665.Fl F 666option some extra attributes (setuid bit set, etc.) are also displayed. 667The colorization is dependent on a terminal type with the proper 668.Xr termcap 5 669capabilities. 670The default 671.Dq Li cons25 672console has the proper capabilities, 673but to display the colors in an 674.Xr xterm 1 , 675for example, 676the 677.Ev TERM 678variable must be set to 679.Dq Li xterm-color . 680Other terminal types may require similar adjustments. 681Colorization 682is silently disabled if the output is not directed to a terminal 683unless the 684.Ev CLICOLOR_FORCE 685variable is defined or 686.Fl -color 687is set to 688.Dq always . 689.It Ev CLICOLOR_FORCE 690Color sequences are normally disabled if the output is not directed to 691a terminal. 692This can be overridden by setting this variable. 693The 694.Ev TERM 695variable still needs to reference a color capable terminal however 696otherwise it is not possible to determine which color sequences to 697use. 698.It Ev COLORTERM 699See description for 700.Ev CLICOLOR 701above. 702.It Ev COLUMNS 703If this variable contains a string representing a 704decimal integer, it is used as the 705column position width for displaying 706multiple-text-column output. 707The 708.Nm 709utility calculates how 710many pathname text columns to display 711based on the width provided. 712(See 713.Fl C 714and 715.Fl x . ) 716.It Ev LANG 717The locale to use when determining the order of day and month in the long 718.Fl l 719format output. 720See 721.Xr environ 7 722for more information. 723.It Ev LSCOLORS 724The value of this variable describes what color to use for which 725attribute when colors are enabled with 726.Ev CLICOLOR 727or 728.Ev COLORTERM . 729This string is a concatenation of pairs of the format 730.Ar f Ns Ar b , 731where 732.Ar f 733is the foreground color and 734.Ar b 735is the background color. 736.Pp 737The color designators are as follows: 738.Pp 739.Bl -tag -width 4n -offset indent -compact 740.It Sy a 741black 742.It Sy b 743red 744.It Sy c 745green 746.It Sy d 747brown 748.It Sy e 749blue 750.It Sy f 751magenta 752.It Sy g 753cyan 754.It Sy h 755light grey 756.It Sy A 757bold black, usually shows up as dark grey 758.It Sy B 759bold red 760.It Sy C 761bold green 762.It Sy D 763bold brown, usually shows up as yellow 764.It Sy E 765bold blue 766.It Sy F 767bold magenta 768.It Sy G 769bold cyan 770.It Sy H 771bold light grey; looks like bright white 772.It Sy x 773default foreground or background 774.El 775.Pp 776Note that the above are standard 777.Tn ANSI 778colors. 779The actual display may differ 780depending on the color capabilities of the terminal in use. 781.Pp 782The order of the attributes are as follows: 783.Pp 784.Bl -enum -offset indent -compact 785.It 786directory 787.It 788symbolic link 789.It 790socket 791.It 792pipe 793.It 794executable 795.It 796block special 797.It 798character special 799.It 800executable with setuid bit set 801.It 802executable with setgid bit set 803.It 804directory writable to others, with sticky bit 805.It 806directory writable to others, without sticky bit 807.El 808.Pp 809The default is 810.Qq "exfxcxdxbxegedabagacad" , 811i.e., blue foreground and 812default background for regular directories, black foreground and red 813background for setuid executables, etc. 814.It Ev LS_COLWIDTHS 815If this variable is set, it is considered to be a 816colon-delimited list of minimum column widths. 817Unreasonable 818and insufficient widths are ignored (thus zero signifies 819a dynamically sized column). 820Not all columns have changeable widths. 821The fields are, 822in order: inode, block count, number of links, user name, 823group name, flags, file size, file name. 824.It Ev LS_SAMESORT 825If this variable is set, the 826.Fl t 827option sorts the names of files with the same modification timestamp in the same 828sense as the time sort. 829See the description of the 830.Fl t 831option for more details. 832.It Ev TERM 833The 834.Ev CLICOLOR 835and 836.Ev COLORTERM 837functionality depends on a terminal type with color capabilities. 838.It Ev TZ 839The timezone to use when displaying dates. 840See 841.Xr environ 7 842for more information. 843.El 844.Sh EXIT STATUS 845.Ex -std 846.Sh EXAMPLES 847List the contents of the current working directory in long format: 848.Pp 849.Dl $ ls -l 850.Pp 851In addition to listing the contents of the current working directory in 852long format, show inode numbers, file flags (see 853.Xr chflags 1 ) , 854and suffix each filename with a symbol representing its file type: 855.Pp 856.Dl $ ls -lioF 857.Pp 858List the files in 859.Pa /var/log , 860sorting the output such that the mostly recently modified entries are 861printed first: 862.Pp 863.Dl $ ls -lt /var/log 864.Sh COMPATIBILITY 865The group field is now automatically included in the long listing for 866files in order to be compatible with the 867.St -p1003.2 868specification. 869.Sh SEE ALSO 870.Xr chflags 1 , 871.Xr chmod 1 , 872.Xr getfacl 1 , 873.Xr sort 1 , 874.Xr xterm 1 , 875.Xr localeconv 3 , 876.Xr strftime 3 , 877.Xr strmode 3 , 878.Xr termcap 5 , 879.Xr maclabel 7 , 880.Xr sticky 7 , 881.Xr symlink 7 , 882.Xr getfmac 8 883.Sh STANDARDS 884With the exception of options 885.Fl g , n 886and 887.Fl o , 888the 889.Nm 890utility conforms to 891.St -p1003.1-2001 . 892The options 893.Fl B , D , G , I , T , U , W , Z , b , h , w , y 894and 895.Fl , 896are compatible extensions not defined in 897.St -p1003.1-2001 . 898.Pp 899The ACL support is compatible with 900.Tn IEEE 901Std\~1003.2c 902.Pq Dq Tn POSIX Ns .2c 903Draft\~17 904(withdrawn). 905.Sh HISTORY 906An 907.Nm 908command appeared in 909.At v1 . 910.Sh BUGS 911To maintain backward compatibility, the relationships between the many 912options are quite complex. 913.Pp 914The exception mentioned in the 915.Fl s 916option description might be a feature that was 917based on the fact that single-column output 918usually goes to something other than a terminal. 919It is debatable whether this is a design bug. 920.Pp 921.St -p1003.2 922mandates opposite sort orders for files with the same timestamp when 923sorting with the 924.Fl t 925option. 926