1.\" Copyright (c) 1980, 1990, 1991, 1993, 1994 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the Institute of Electrical and Electronics Engineers, Inc. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgment: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)ls.1 8.7 (Berkeley) 7/29/94 36.\" $FreeBSD$ 37.\" 38.Dd July 29, 1994 39.Dt LS 1 40.Os 41.Sh NAME 42.Nm ls 43.Nd list directory contents 44.Sh SYNOPSIS 45.Nm ls 46.Op Fl ABCFGHLPRTWabcdfgiklnoqrstu1 47.Op Ar file ... 48.Sh DESCRIPTION 49For each operand that names a 50.Ar file 51of a type other than 52directory, 53.Nm 54displays its name as well as any requested, 55associated information. 56For each operand that names a 57.Ar file 58of type directory, 59.Nm 60displays the names of files contained 61within that directory, as well as any requested, associated 62information. 63.Pp 64If no operands are given, the contents of the current 65directory are displayed. 66If more than one operand is given, 67non-directory operands are displayed first; directory 68and non-directory operands are sorted separately and in 69lexicographical order. 70.Pp 71The following options are available: 72.Bl -tag -width indent 73.It Fl A 74List all entries except for 75.Ql \&. 76and 77.Ql \&.. . 78Always set for the super-user. 79.It Fl B 80Force printing of non-graphic characters in file names as \\xxx, 81where xxx is the numeric value of the character in octal. 82.It Fl C 83Force multi-column output; this is the default when output is to a terminal. 84.It Fl F 85Display a slash (/) immediately after each pathname 86that is a directory, an asterisk (*) after each that is 87executable, 88an at sign (@) after each symbolic link, 89an equals sign (=) after each socket, 90a percent sign (%) after each whiteout, 91and a vertical bar (|) after each that is a 92.Tn FIFO . 93.It Fl G 94Use ANSI color sequences to distinguish file types. (See 95.Ev LSCOLORS 96below.) In addition to those mentioned above in 97.Fl F , 98some extra attributes (setuid bit set, etc.) are also displayed. 99.It Fl H 100Symbolic links on the command line are followed. This option is assumed if 101none of the 102.Fl F , 103.Fl d , 104or 105.Fl l 106options are specified. 107.It Fl L 108If argument is a symbolic link, list the file or directory the link references 109rather than the link itself. 110This option cancels the 111.Fl P 112option. 113.It Fl P 114If argument is a symbolic link, list the link itself rather than the 115object the link references. This option cancels the 116.Fl H 117and 118.Fl L 119options. 120.It Fl R 121Recursively list subdirectories encountered. 122.It Fl T 123Display complete time information for the file, including 124month, day, hour, minute, second, and year. 125.It Fl W 126Display whiteouts when scanning directories. 127.It Fl a 128Include directory entries whose names begin with a 129dot (.). 130.It Fl b 131As 132.Fl B , 133but use C escape codes whenever possible. 134.It Fl c 135Use time when file status was last changed for sorting or printing. 136.It Fl d 137Directories are listed as plain files (not searched recursively). 138.It Fl f 139Output is not sorted. 140.It Fl g 141This option is deprecated and is only available for compatibility 142with 143.Bx 4.3 ; 144it was used to display the group name in the long 145.Pq Fl l 146format output. 147.It Fl i 148For each file, print the file's file serial number (inode number). 149.It Fl k 150If the 151.Fl s 152option is specified, print the file size allocation in kilobytes, 153not blocks. This option overrides the environment variable BLOCKSIZE. 154.It Fl l 155(The lowercase letter ``ell.'') List in long format. 156(See below.) 157If the output is to a terminal, a total sum for all the file 158sizes is output on a line before the long listing. 159.It Fl n 160Display user and group IDs numerically rather than converting to a user 161or group name in a long 162.Pq Fl l 163output. 164.It Fl o 165Include the file flags in a long 166.Pq Fl l 167output. 168.It Fl q 169Force printing of non-graphic characters in file names as 170the character `?'; this is the default when output is to a terminal. 171.It Fl r 172Reverse the order of the sort to get reverse 173lexicographical order or the oldest entries first. 174.It Fl s 175Display the number of file system blocks actually used by each file, in units 176of 512 bytes, where partial units are rounded up to the next integer value. 177If the output is to a terminal, a total sum for all the file 178sizes is output on a line before the listing. The environment variable 179BLOCKSIZE overrides the unit size of 512 bytes. 180.It Fl t 181Sort by time modified (most recently modified 182first) before sorting the operands by lexicographical 183order. 184.It Fl u 185Use time of last access, 186instead of last modification 187of the file for sorting 188.Pq Fl t 189or printing 190.Pq Fl l . 191.It Fl \&1 192(The numeric digit ``one.'') Force output to be 193one entry per line. 194This is the default when 195output is not to a terminal. 196.El 197.Pp 198The 199.Fl 1 , 200.Fl C , 201and 202.Fl l 203options all override each other; the last one specified determines 204the format used. 205.Pp 206The 207.Fl c 208and 209.Fl u 210options override each other; the last one specified determines 211the file time used. 212.Pp 213The 214.Fl B , 215.Fl b 216and 217.Fl q 218options all override each other; the last one specified determines 219the format used for non-printable characters. 220.Pp 221The 222.Fl H, 223.Fl L 224and 225.Fl P 226options all override each other (either partially or fully); they 227are applied in the order specified. 228.Pp 229By default, 230.Nm 231lists one entry per line to standard 232output; the exceptions are to terminals or when the 233.Fl C 234option is specified. 235.Pp 236File information is displayed with one or more 237<blank>s separating the information associated with the 238.Fl i , 239.Fl s , 240and 241.Fl l 242options. 243.Ss The Long Format 244If the 245.Fl l 246option is given, the following information 247is displayed for each file: 248file mode, 249number of links, owner name, group name, 250number of bytes in the file, abbreviated 251month, day-of-month file was last modified, 252hour file last modified, minute file last 253modified, and the pathname. 254In addition, for each directory whose contents are displayed, the total 255number of 512-byte blocks used by the files in the directory is displayed 256on a line by itself immediately before the information for the files in the 257directory. 258.Pp 259If the modification time of the file is more than 6 months 260in the past or future, then the year of the last modification 261is displayed in place of the hour and minute fields. 262.Pp 263If the owner or group names are not a known user or group name, 264or the 265.Fl n 266option is given, 267the numeric ID's are displayed. 268.Pp 269If the file is a character special or block special file, 270the major and minor device numbers for the file are displayed 271in the size field. 272If the file is a symbolic link the pathname of the 273linked-to file is preceded by 274.Dq \-> . 275.Pp 276The file mode printed under the 277.Fl l 278option consists of the 279entry type, owner permissions, and group permissions. 280The entry type character describes the type of file, as 281follows: 282.Pp 283.Bl -tag -width 4n -offset indent -compact 284.It Sy b 285Block special file. 286.It Sy c 287Character special file. 288.It Sy d 289Directory. 290.It Sy l 291Symbolic link. 292.It Sy s 293Socket link. 294.It Sy p 295.Tn FIFO . 296.It Sy \- 297Regular file. 298.El 299.Pp 300The next three fields 301are three characters each: 302owner permissions, 303group permissions, and 304other permissions. 305Each field has three character positions: 306.Bl -enum -offset indent 307.It 308If 309.Sy r , 310the file is readable; if 311.Sy \- , 312it is not readable. 313.It 314If 315.Sy w , 316the file is writable; if 317.Sy \- , 318it is not writable. 319.It 320The first of the following that applies: 321.Bl -tag -width 4n -offset indent 322.It Sy S 323If in the owner permissions, the file is not executable and 324set-user-ID mode is set. 325If in the group permissions, the file is not executable 326and set-group-ID mode is set. 327.It Sy s 328If in the owner permissions, the file is executable 329and set-user-ID mode is set. 330If in the group permissions, the file is executable 331and setgroup-ID mode is set. 332.It Sy x 333The file is executable or the directory is 334searchable. 335.It Sy \- 336The file is neither readable, writable, executable, 337nor set-user-ID nor set-group-ID mode, nor sticky. 338(See below.) 339.El 340.Pp 341These next two apply only to the third character in the last group 342(other permissions). 343.Bl -tag -width 4n -offset indent 344.It Sy T 345The sticky bit is set 346(mode 347.Li 1000 ) , 348but not execute or search permission. 349(See 350.Xr chmod 1 351or 352.Xr sticky 8 . ) 353.It Sy t 354The sticky bit is set (mode 355.Li 1000 ) , 356and is searchable or executable. 357(See 358.Xr chmod 1 359or 360.Xr sticky 8 . ) 361.El 362.El 363.Sh DIAGNOSTICS 364The 365.Nm 366utility exits 0 on success, and >0 if an error occurs. 367.Sh ENVIRONMENT 368The following environment variables affect the execution of 369.Nm Ns : 370.Bl -tag -width BLOCKSIZE 371.It Ev BLOCKSIZE 372If the environment variable 373.Ev BLOCKSIZE 374is set, the block counts 375(see 376.Fl s ) 377will be displayed in units of that size block. 378.It COLUMNS 379If this variable contains a string representing a 380decimal integer, it is used as the 381column position width for displaying 382multiple-text-column output. 383The 384.Nm 385utility calculates how 386many pathname text columns to display 387based on the width provided. 388(See 389.Fl C . ) 390.It Ev TZ 391The timezone to use when displaying dates. 392See 393.Xr environ 7 394for more information. 395.It LSCOLORS 396The value of this variable describes what color to use for which 397attribute when the color output 398.Pq Fl G 399is specified. This string is a concatenation of pairs of the format 400.Sy fb , 401where 402.Sy f 403is the foreground color and 404.Sy b 405is the background color. 406.Pp 407The color designators are as follows: 408.Pp 409.Bl -tag -width 4n -offset indent -compact 410.It Sy 0 411black 412.It Sy 1 413red 414.It Sy 2 415green 416.It Sy 3 417brown 418.It Sy 4 419blue 420.It Sy 5 421magenta 422.It Sy 6 423cyan 424.It Sy 7 425light grey 426.It Sy x 427default foreground or background 428.El 429.Pp 430(Note: the above are standard ANSI colors. The actual display may 431differ depending on the color capabilities of your terminal.) 432.Pp 433The order of the attributes are as follows: 434.Pp 435.Bl -enum -offset indent -compact 436.It 437directory 438.It 439symbolic link 440.It 441socket 442.It 443pipe 444.It 445executable 446.It 447block special 448.It 449character special 450.It 451executable with setuid bit set 452.It 453executable with setgid bit set 454.It 455directory writable to others, with sticky bit 456.It 457directory writable to others, without sticky bit 458.El 459.Pp 460The default is "4x5x2x3x1x464301060203", i.e., blue foreground and 461default background for regular directories, black foreground and red 462background for setuid executables, etc. 463.It Ev LS_COLWIDTHS 464If this variable is set, it is considered to be a 465colon-delimited list of minimum column widths. Unreasonable 466and insufficient widths are ignored (thus zero signifies 467a dynamically sized column). Not all 468columns have changeable widths. The fields are, 469in order: inode, block count, number of links, user name, 470group name, flags, file size, file name. 471.El 472.Sh COMPATIBILITY 473The group field is now automatically included in the long listing for 474files in order to be compatible with the 475.St -p1003.2 476specification. 477.Sh SEE ALSO 478.Xr chflags 1 , 479.Xr chmod 1 , 480.Xr symlink 7 , 481.Xr sticky 8 482.Sh HISTORY 483An 484.Nm 485command appeared in 486.At v1 . 487.Sh STANDARDS 488The 489.Nm 490function is expected to be a superset of the 491.St -p1003.2 492specification. 493.Sh BUGS 494To maintain backward compatibility, the relationships between the many 495options is quite complex. 496