Home | History | Annotate | Download | only in ls
History log of /src/bin/ls/ls.c
RevisionDateAuthorComments
 1.79  11-Dec-2024  simonb Use the number of blocks used in the current directory instead of the
total file byte count when printing the initial "total" line with the
-h option combined with -s or -l options.
 1.78  02-Feb-2024  christos branches: 1.78.2;
PR/57892: Roberto Branco: Print full pathname in error messages
 1.77  07-Jul-2020  christos branches: 1.77.6;
Fix skipping of directories that begin with a '.' in -R mode.
It is not enough to avoid displaying the contents of the directory,
we need to set FTS_SKIP to avoid descending into any subdirs too.
Otherwise, if a ".foo" directory has a subdirectory "bar", ls will
descend into bar and display its contents. From Todd Miller
 1.76  06-Feb-2017  rin branches: 1.76.12;
white space
 1.75  30-May-2016  dholland branches: 1.75.2; 1.75.4;
PR 50997 David Binderman: fix format strings
 1.74  02-Apr-2014  wiz Apply diff from Igor Sobrado <isd@orion.ciencias.uniovi.es>:

We have written a diff to our ls(1) to recover the traditional behaviour
of -f implying -a. This change does not only accommodates POSIX.1
but also matches traditional UNIX.

OpenBSD commit message:

CVSROOT: /cvs
Module name: src
Changes by: sobrado@cvs.openbsd.org 2014/03/31 14:54:37

Modified files:
bin/ls : ls.1 ls.c

Log message:
restore the traditional behavior of -f implying -a; apparently Keith Bostic
forgot to restore it when the -f flag was put back on 2nd of September 1989,
after being removed on 16th of August as a consequence of issues getting it
working over NFS, so deviation from traditional UNIX behavior in all BSDs
looks like an historical accident; as a side effect, this change accommodates
behavior of this option to IEEE Std 1003.1-2008 (``POSIX.1'').

joint work with jmc@ (who found the inaccuracy in our implementation),
schwarze@ (who provided a detailed tracking of historical facts) and millert@

ok millert@, schwarze@
 1.73  22-Feb-2014  mlelstv add u option to getopt again.
 1.72  21-Feb-2014  christos Add -X (don't cross mount points when recursing) from tls@
 1.71  20-Feb-2014  christos Add -O (only leaf files) and -P (print full path), from tls@
 1.70  20-Nov-2012  abs PR/47167
ls.1:
- Sort options in `SYNOPSIS', the option list, and texts within
the man page;
- improve wording;
- improve macro usage;
- use more consistency regarding (locations for) information about
which options override which;
- cross-reference `-d' and `-R';
- simplify description of `-k', removing redundant and unneeded
information;
- sort entry type list (but leave `-a' and `-A' as they are, given
their meaning);
- correct / augment description of `BLOCKSIZE' environment variable
in `ENVIRONMENT' section;
- bump date.

ls.c:
- Sort options in `usage';
- augment comment about when to figure out block size.
 1.69  29-Aug-2011  joerg branches: 1.69.2; 1.69.8;
Move usage and mark it static+dead
 1.68  15-Mar-2011  erh PR#7540, add a -M option to ls which causes sizes (and number of blocks) to be
displayed with comma separators (or a locale specific separator).
 1.67  08-Jul-2010  rmind Add #include <sys/param.h> for howmany().
 1.66  14-Feb-2009  lukem fix -Wsign-compare issues
 1.65  25-Sep-2008  lukem branches: 1.65.6;
Change '-n' so that it implies '-l' rather than requires '-l'.
Brings ls(1) closer to POSIX.1 2004.
Per discussion with Thomas Klausner and Igor Sobrado.
 1.64  20-Jul-2008  lukem Remove the \n and tabs from the __COPYRIGHT() strings.
 1.63  14-Dec-2006  he branches: 1.63.12;
Complete the move of string_to_flags() and flags_to_string() from the
bin/ls sources to libutil:
o Bump libutil minor version number
o Fix uses to include <util.h> to pick up the function definitions
o Fix most uses of flags_to_string() to release the now-malloc()ed result
 1.62  14-Dec-2006  christos Pass lint. From Anon Ymous
 1.61  23-Sep-2006  elad PR/34499: mac at S dot culver dot net: ls allocates more memory than needed
Applied patch, thanks!
 1.60  21-Aug-2006  christos from zafer: you can have either -k or -h but not both since it does not make
sense.
 1.59  22-Mar-2006  christos branches: 1.59.2;
Coverity CID 1755: Add fts_close() in traverse.
 1.58  26-Oct-2005  jschauma Rather than '-h' suppressing '-s' when using '-l', make it display
the blocks used in human readable form, as suggested by Alan Barrett
and Daniel Carosone.
 1.57  14-Oct-2005  jschauma Honor the COLUMNS variable even when producing output not to a terminal,
as long as a specific format (that could use COLUMNS) was requested.
This makes

env COLUMNS=50 ls -C > file

not surprise the user who clearly wanted some specific output in the file.
 1.56  17-Jun-2005  hira - Add -h to usage.
- Use set/getprogname(3).
 1.55  26-Dec-2003  simonb Fix bug with previous change- always initialise d.s_block. Now "ls -1sh"
works.
XXX: ls -sh now always uses 4 chars for the size column width even if it
needs less than that.
 1.54  26-Dec-2003  simonb KNF - wrap long lines.
 1.53  26-Dec-2003  grant implement -h(umanize).

from David P. Reese Jr. in PR bin/23870.
 1.52  22-Sep-2003  jschauma After last weeks addition of the '-b' flag, add '-B' and '-w' flags,
suggested by uwe@, inspired by FreeBSD. The three flags override
each other (and the '-q' flag) and behave as follows:

-B Force printing of non-printable characters in file names as
\xxx, where xxx is the numeric value of the character in octal.

-b As -B, but use C escape codes whenever possible.

-w Force raw printing of non-printable characters. This is the
default when output is not to a terminal.
 1.51  14-Sep-2003  jschauma Implement '-b' option, which, following FreeBSD, Linux and (I think) Solaris
prints octal escapes for nongraphic characters.
 1.50  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22249, verified by myself.
 1.49  30-May-2003  simonb Pass a NULL to getbsize() for any arguments that aren't needed, and
remove the otherwise unused variables.
 1.48  11-May-2003  kleink If both -g and -l options are present, let -l take precedence over -g,
as requested by several users.

POSIX-2001 is unclear on conflicting option letters as far as the -g
option is concerned; a clarification request will be made.

Addresses PR bin/21519 by Geoff Wing.
 1.47  07-May-2003  simonb Add a FALLTHROUGH to keep lint happy.
 1.46  07-May-2003  grant make -g behave as it should according to SUSv3 (long listing without
owner).

ok'd by kleink@.
 1.45  27-Sep-2002  simonb Need to initialise the blocksize variable if the -i option is used
too. The code in display() could possibly be a bit smarter about this
requirement...

Fixes the problem in PR bin/18321 from David Laight and PR bin/18436
from FUKAUMI Naoki.
 1.44  14-Sep-2002  sommerfeld Use the output blocksize when computing how much room to leave for the
-s option, to suppress unnecessary leading spaces.
 1.43  29-Jul-2000  lukem convert to new KNF
 1.42  17-Jun-2000  assar Do not modify the file name when not printing non-printables, also do
it consistently with the file name and possible symbolic link target.

fixes bin/10385 and bin/10384
 1.41  06-Mar-2000  enami branches: 1.41.2;
- Fix a typo that when group_from_gid is failed (though it merely fails
on NetBSD), numeric gid string is used as `user'.
- Don't mix use %u and %d for numeric uid/gid.
- Share temporary buffer.
 1.40  09-Nov-1999  drochner Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
 1.39  02-Nov-1999  tron Call setlocale(3) to use localization in "ls" as suggested by
Jens A Nilsson in PR bin/8730.
 1.38  17-May-1999  lukem branches: 1.38.2;
Rename ls.c::main() -> ls.c::ls_main(), and add a wrapper in main.c::main().
This allows other programs to link in against ls (e.g, ftpd), without having
to have hacks to deal with multiple main()s.

Yes, I know this is ugly. The clean alternative (move lots of this
into libutil, yada yada yada) isn't fun, and the effort probably isn't
justified...
 1.37  04-May-1999  simonb If an error is encountered, exit with non-zero status.

Based on FreeBSD fix (in 1996!), and fixes PR bin/7514 from
Jorgen Pehrson.
 1.36  17-Feb-1999  kleink branches: 1.36.2;
Add support for the XCU5 -p option (-F restricted to directories).
 1.35  12-Feb-1999  kleink Implement 1003.2 -m option (stream output format).
 1.34  04-Nov-1998  christos %q -> %ll
 1.33  04-Nov-1998  christos include termios.h for struct winsize
 1.32  13-Oct-1998  wsanchez Check for NULL value returned by user_from_uid and group_from_gid and DTRT,
rather than crash.
 1.31  19-Aug-1998  thorpej Add some braces to make egcs happy.
 1.30  28-Jul-1998  mycroft Delint.
 1.29  28-Jul-1998  mycroft Delint.
 1.28  27-Jul-1998  mycroft Slight code reduction.
 1.27  27-Jul-1998  mycroft __AUDIT__ cleanup.
 1.26  16-May-1998  lukem * blocks can be 64bit (not u_long), so calculate and display accordingly
* cleanup some other typedamage (int is as good as u_long)
* remove unused variables
 1.25  03-Feb-1998  mycroft Deal with GCC warning.
 1.24  18-Jan-1998  lukem * implement -x; sort columns across the page rather than down the page
* in printcol(), don't bother building an index to the linked list if
only printing one column with printscol()...
* implement -n; prevent [gu]id->name mapping in long listings.
inspired by openbsd, but does *not* imply -l by itself.
* fix sorting with -d (or mismatched types in general). (from openbsd).
* document -g. (from openbsd).
 1.23  17-Jan-1998  mycroft Automatically resize the major and minor number fields, and DTRT if the size
field is not the same size.
 1.22  30-Jul-1997  thorpej branches: 1.22.2;
Add some casts to printf args to keep the compiler happy on the Alpha.
 1.21  20-Jul-1997  christos include <pwd.h> and <grp.h> to bring prototypes into scope.
 1.20  20-Jul-1997  christos remove user_from_uid and group_from_gid prototypes.
 1.19  20-Jul-1997  christos Fix compiler warnings.
Add WARNS=1
 1.18  09-Jul-1996  mycroft Sort FTS_NS entries by name, just so the order is well-defined.
 1.17  08-Jul-1996  mycroft Partition FTS_NS entries from others, to avoid confusing qsort().
Don't bother to order the FTS_NS entries amongst themselves.
 1.16  14-Feb-1996  jtc branches: 1.16.4;
Changed so that COLUMNS environment variable will override the value
obtained via the TIOCGWINSIZ ioctl. This is required by POSIX.2, see
section 4.39.5.3.
 1.15  07-Sep-1995  jtc Sync with 4.4lite2
 1.14  21-Mar-1995  cgd convert to new RCS id conventions.
 1.13  27-Dec-1994  mycroft Sync with CSRG.
 1.12  23-Sep-1994  mycroft Merge with 4.4-Lite version.
 1.11  08-Apr-1994  jtc Changed traverse() and display() so that errors are reported when
they are first detected in display(), rather than waiting until later
in traverse().

The old code allowed "Can not read directory" error messages to be
left unreported unless the -R (recurse) option was used.
 1.10  04-Apr-1994  chopps "yet" on quad_t/off_t things. (not noticed on i386 becuase of endian I guess.)
 1.9  25-Jan-1994  cgd (1) fixup getbsize() calls
(2) convert to use err(), warn(), and warnx(), as appropriate.
 1.8  05-Dec-1993  mycroft Patches from Thomas Eberhardt <thomas@mathematik.uni-Bremen.de> to allow
sorting by size.
 1.7  07-Aug-1993  mycroft New version from uunet, with -k option readded, and 4.4 ffs--specific stuff
in `#ifdef notyet'.
 1.6  01-Aug-1993  mycroft Add RCS identifiers.
 1.5  26-May-1993  deraadt previous patch to ls.c wasn't quite correct. This patch from same author.
 1.4  24-May-1993  deraadt first environment variable was trounced in the case of
"ls -l". Patch from <bob@obiwan.uucp> Bob Willcox
 1.3  23-Mar-1993  cgd changed "Id" to "Header" for rcsids
 1.2  22-Mar-1993  cgd added rcs ids to all files
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  07-Sep-1995  jtc imported from 44lite2
 1.1.1.2  22-Sep-1994  mycroft Import original 4.4-Lite version.
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.16.4.1  10-Dec-1996  mycroft From trunk:
Various changes to make the sorting deterministic (and correct).
 1.22.2.1  09-Feb-1998  mellon Pull up 1.23 (mycroft)
 1.36.2.1  09-Sep-2000  he Pull up revision 1.37 (requested by hubertf):
Exit with non-zero status if an error was encountered. Fixes
PR#7514.
 1.38.2.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.41.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.59.2.1  27-Aug-2006  riz Pull up following revision(s) (requested by christos in ticket #53):
bin/df/df.c: revision 1.71
bin/mv/mv.c: revision 1.36
bin/ls/ls.1: revision 1.61
bin/ls/ls.c: revision 1.60
-h and -[mgk] are mutually exclusive. Only use the last specified. [from zafer]
Use one variable instead of 3 flags to hold the scale, so that we don't have
to reset each flag.
from zafer: you can have either -k or -h but not both since it does not make
sense.
- detect buffer overflow.
- if we have a trailing slash, don't add another one.
 1.63.12.1  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.65.6.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.69.8.2  19-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.69.8.1  25-Feb-2013  tls resync with head
 1.69.2.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.69.2.1  16-Jan-2013  yamt sync with (a bit old) head
 1.75.4.1  21-Apr-2017  bouyer Sync with HEAD
 1.75.2.1  20-Mar-2017  pgoyette Sync with HEAD
 1.76.12.2  21-Apr-2020  martin Ooops, restore accidently removed files from merge mishap
 1.76.12.1  21-Apr-2020  martin Sync with HEAD
 1.77.6.1  20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #743):

bin/ls/ls.c: revision 1.78

PR/57892: Roberto Branco: Print full pathname in error messages
 1.78.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed