Commit Graph

98 Commits

Author SHA1 Message Date
Kyle Evans
e10ba80063 ls(1): Add --color=when
--color may be set to one of: 'auto', 'always', and 'never'.

'auto' is the default behavior- output colors only if -G or COLORTERM are
set, and only if stdout is a tty.

'always' is a new behavior- output colors always. termcap(5) will be
consulted unless TERM is unset or not a recognized terminal, in which case
ls(1) will fall back to explicitly outputting ANSI escape sequences.

'never' to turn off any environment variable and -G usage.

Reviewed by:	cem, 0mp (both modulo last-minute manpage changes
Differential Revision:	https://reviews.freebsd.org/D16741
2018-08-17 04:15:51 +00:00
Conrad Meyer
0fdf7fa846 Convert ls(1) to not use libxo(3)
libxo imposes a large burden on system utilities. In the case of ls, that
burden is difficult to justify -- any language that can interact with json
output can use readdir(3) and stat(2).

Logically, this reverts r291607, r285857, r285803, r285734, r285425,
r284494, r284489, r284252, and r284198.

Kyua tests continue to pass (libxo integration was entirely untested).

Reported by:	many
Reviewed by:	imp
Discussed with:	manu, bdrewery
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D13959
2018-01-17 22:47:34 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Konstantin Belousov
cdf44896bb Use uintmax_t to print st_nlink.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2017-02-16 06:32:39 +00:00
Baptiste Daroussin
be90c1c6b5 Fix ls -l alignement with new locales
Latest update of locales introduced abbreviated month that follows the regionale
rules meaning that they can be of variable length instead of being arbitrary
truncated to top 3 characters.

To fix alignement, ls now computes the visible length of the abbreviated month,
pads the shorter month with spaces in order to make sure everything is properly
aligned

Reviewed by:	ache, ed, jilles
Differential Revision:	https://reviews.freebsd.org/D4239
2015-12-07 20:48:28 +00:00
Allan Jude
e9eed90c39 Cast uid and gid to the correct type for display to solve segfault in ls(1) on 32bit arches
Correctly escape literal % for display

This fixes segfaults in 32bit arches caused by r285734

Reviewed by:	ngie
Approved by:	dim
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D3191
2015-07-24 20:20:59 +00:00
Allan Jude
ddaf675fc8 Remove an excess space accidently introduced in the output in ls(1) by r285734
Spotted by:	dim
Approved by:	eadler (mentor)
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D3152
2015-07-22 19:58:21 +00:00
Allan Jude
e5542be424 Fix some issues with the application of libxo to ls(1)
* Add whitespace trimming to some fields (username, group, size, inode, blocks) to avoid whitespace in JSON strings
* fix -m mode, was invalid JSON (repeated keys), and was missing outer array container
* in -n mode, numeric uids and gids were returned as strings

Approved by:	eadler (mentor)
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D2854
2015-07-21 05:03:59 +00:00
Alexander Kabaev
0d5beab5be Continue ubreaking ``env LANG=ru_RU.KOI8-R ls -l''.
File names are in current locale as well.
2015-06-17 04:26:48 +00:00
Marcel Moolenaar
284e2b82b2 Unbreak ``env LANG=ru_RU.KOI8-R ls -l''.
Time strings are in the current locale.
2015-06-17 03:12:08 +00:00
Sean Bruno
a0be738b20 r284198 seems to have left a null format string printf that gcc does *not*
like breaking mips builds.

Submitted by:	Shawn Webb <shawn.webb@hardenedbsd.org>
Obtained from:	HardenedBSD
2015-06-11 02:29:39 +00:00
Marcel Moolenaar
52e4a08c45 Convert ls(1) to use libxo(3).
Obtained from:	Phil Shafer <phil@juniper.net>
Sponsored by:	Juniper Networks, Inc.
2015-06-10 01:27:38 +00:00
Peter Wemm
d272a5b786 Undo over-aggressive conversion of spaces to tabs. ie: those within
format strings, "period, space, space" in comment text, etc.
2012-11-09 20:19:56 +00:00
Greg Lehey
dfd91f79a3 Replace spaces with tabs where appropriate.
Reminded by: jh@
2012-11-08 23:45:19 +00:00
Greg Lehey
9aa68a3ffa Add y flag and environment variable LS_SAMESORT to specify the same
sorting order for time and name with the -t option.  IEEE Std 1003.2
(POSIX.2) mandates that the -t option sort in descending order, and
that if two files have the same timestamp, they should be sorted in
ascending order of their names.  The -r flag reverses both of these
sort orders, so they're never the same.  This creates significant
problems for sequentially named files stored on FAT file systems,
where it can be impossible to list them in the order in which they
were created.

Add , (comma) option to print file sizes grouped and separated by
thousands using the non-monetary separator returned by localeconv(3),
typically a comma or period.

MFC after:  14 days
2012-11-08 00:24:26 +00:00
Matthew D Fleming
6db1a7f11e Fix bin/ build with a 64-bit ino_t.
Original code by:	Gleb Kurtsou
2012-09-27 23:31:12 +00:00
Ed Schouten
9f365aa1d6 Get rid of major/minor number distinction.
As of FreeBSD 6, devices can only be opened through devfs. These device
nodes don't have major and minor numbers anymore. The st_rdev field in
struct stat is simply based a copy of st_ino.

Simply display device numbers as hexadecimal, using "%#jx". This is
allowed by POSIX, since it explicitly states things like the following
(example taken from ls(1)):

	"If the file is a character special or block special file, the
	size of the file may be replaced with implementation-defined
	information associated with the device in question."

This makes the output of these commands more compact. For example, ls(1)
now uses approximately four columns less. While there, simplify the
column length calculation from ls(1) by calling snprintf() with a NULL
buffer.

Don't be afraid; if needed one can still obtain individual major/minor
numbers using stat(1).
2011-09-28 18:53:36 +00:00
Jaakko Heinonen
55926a6616 Fixes for ls(1) long format (-l) output:
- Allow -h option to work if the listing contains at least one device
  file.
- Align major and minor device numbers correctly to the size field.

PR:		bin/125678
Approved by:	trasz (mentor)
MFC after:	1 month
2010-01-24 19:23:07 +00:00
Edward Tomasz Napierala
a34292623f Fix regression introduced in r196712 - the 'name' string needs
to be rewritten for each file we want to check ACL on.  Without
this change, ls(1) would check only the ACL on the first file
to list.
2009-09-02 20:50:39 +00:00
Edward Tomasz Napierala
f7b8687a93 Add NFSv4 ACL support to ls(1). 2009-08-31 20:53:01 +00:00
Warner Losh
2af52e0724 Turn a tab into a space. This fixes a misalignment for ls -l.
Tabs Noticed by: Antoine Brodin
2008-04-05 21:26:25 +00:00
Greg Lehey
2269fa5765 Add -D option to specify exact format of date and time output with ls -l. 2008-04-04 03:57:46 +00:00
Ruslan Ermilov
b912fe73ee Avoid a spurious warning for each whiteout found during "ls -lW".
# ls -lW
total 2
-rw-r--r--  1 root  wheel  6 Oct 18 14:46 file1
ls: ./file2: No such file or directory
w---------  0 root  wheel  0 Jan  1  1970 file2
2006-10-18 10:58:27 +00:00
John Baldwin
fe79420eb7 Add a new -U flag to instruct ls to use the birthtime for printing or
sorting.

Submitted by:	Andrzej Tobola ato at iem dot pw dot edu dot pl
MFC after:	1 week
2006-03-24 16:38:02 +00:00
Warner Losh
9ddb49cbe4 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
David Schultz
48a91b69b8 Remove from the printfns the assumption that dp->list != NULL. Even
if there are no entries, these functions may be called to print the
total number of blocks (0) for consistency's sake.
2004-06-08 09:27:42 +00:00
Pawel Jakub Dawidek
478aa80510 Use humanize_number(3).
Reminded by:	jhb
2004-05-25 14:53:47 +00:00
Tim J. Robbins
107409f46e Treat filenames as multibyte character strings (according to the current
LC_CTYPE setting) when determining which characters are printable.
This is an often-requested feature.

Use wcwidth() to determine the number of column positions a character
takes up, although there are still a few places left where we assume
1 byte = 1 column position, e.g. line-wrapping when handling the -m option.

The error handling here is somewhat more complicated than usual: we do
our best to show what we can of a filename in the presence of conversion
errors, instead of simply aborting.
2004-05-02 11:25:37 +00:00
Mark Murray
6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Bosko Milekic
263377339c Stop iterating over ACLs if we've already determined we
will print them (i.e., number of successful calls to acl_get_entry()
exceeds 3).  This makes O(1) what was O(num_TYPE_ACCESS_ACLs).

This is a slightly modified version of submitter's patch.

PR: bin/65042
Submitted by: Christian S.J. Peron <maneo@bsdpro.com>
2004-04-03 16:55:56 +00:00
Colin Percival
310924af3d Fixes to output of ls -lh for certain file sizes:
1. Sizes in the range 1000 -- 1023 units require four characters width
   for the integer; increase the field width to accomodate this.
2. Sizes in the range 9.95 -- 10 units were being displayed as "10.0"
   units; adjust the logic to fix this, and now that we've got an extra
   character of field width, print fractional units if the size is less
   than 99.95 units.
3. Don't display sub-byte precision.

This should mean that the following sizes are displayed:
    0B .. 1023B
  1.0U ..  9.9U
 10.0U .. 99.9U
  100U .. 1023U
for values of U in "KMGTPE".

PR:		bin/63547
Pointy hat to:	cperciva
Approved by:	rwatson (mentor)
2004-03-01 19:25:27 +00:00
Colin Percival
d3b68bf14c Fix alignment of size field in ls -lh -- the width was being computed
from log[10](largest file size), but when outputting in human-friendly
format the width is always at most 4. (eg. "123K", " 12K", "1.2K".)

PR: bin/59320
Approved by: rwatson (mentor)
2004-01-22 04:33:00 +00:00
Tim J. Robbins
c5bc87095b Handle realloc() failure correctly. 2003-10-16 07:07:20 +00:00
Mark Murray
40feca3a99 Fix a bazillion warnings. This makes almost the whole of src/bin/*
WARNS=6, std=c99 clean.

Tested on:	i386, alpha
2003-05-03 16:39:34 +00:00
Tim J. Robbins
3fceb9fd5b pathconf() and acl_get_file() follow links so they cannot be used to
determine whether a symlink has an ACL. Instead, assume that symbolic
links don't have ACLs and don't bother checking. Avoids spurious
ENOENT warnings when listing directories containing broken symlinks
on filesystems with ACLs enabled.

Pointed out by:	rwatson, bde
2002-12-19 01:13:23 +00:00
Tim J. Robbins
e09fdabddf Use warn() instead of perror() or fprintf() where appropriate. 2002-11-06 01:18:12 +00:00
Tim J. Robbins
dd9aaeb0f7 Print a `+' character after the standard UNIX permission fields in long
listings if the file has an extended ACL (more than the required 3 entries).
This is what Solaris and IRIX do, and what the withdrawn POSIX.2c standard
required.

Reviewed by:	rwatson (an earlier version of the patch)
2002-11-03 07:29:08 +00:00
Robert Watson
4d33b62edc Teach "ls -Z" to use the policy-agnostic MAC label interfaces rather
than the LOMAC-specific interfaces for listing MAC labels.  This permits
ls to view MAC labels in a manner similar to getfmac, when ls is used
with the -l argument.  Next generation LOMAC will use the MAC Framework
so should "just" work with this and other policies.  Not the prettiest
code in the world, but then, neither is ls(1).

Obtained from:	TrustedBSD Project
Sponsored by:	DARPA, Network Associates Laboratories
2002-10-24 00:07:30 +00:00
Mark Murray
ca2993fb41 Constify, staticify, rationalise types and fix other related warnings. 2002-10-23 10:20:01 +00:00
Tim J. Robbins
1656f85050 Print non-printing characters in directory names, as well as file names,
as `?' or `\ooo', depending on whether the -b or -B flags were used.

PR:		43995
MFC after:	1 month
2002-10-18 10:59:45 +00:00
Dima Dorfman
598420ee63 Output "human-readable" values with a non-0 precision where
appropriate.  Before this, a 2.9 GB file was misleadingly reported as
"2G".  This mostly brings unit_adjust() in line with what is in du(1).

Reviewed by:	jmallett
Approved by:	nik
2002-10-18 04:06:59 +00:00
Giorgos Keramidas
872b3fe268 Fix a warning of "possibly used before initialisation".
Reviewed by:	tjr
2002-08-29 14:29:09 +00:00
David E. O'Brien
5eb43ac2f7 Consistently use __FBSDID 2002-06-30 05:13:54 +00:00
Tim J. Robbins
94274c73cb Add missing options required by SUSv3:
-m	List files across the page, separated by commas.
-p	Print a slash after directory names
-x	Same as -C but sort across the columns rather than down

Submitted by:	Kyle Martin <mkm@ieee.org>
2002-05-19 02:51:36 +00:00
Bill Fumerola
568dcd5fca restore missing default case removed in ls.c:r1.57
add break statements to default cases where missing.

Submitted by:	bde
2002-05-15 18:53:56 +00:00
Bruce Evans
434b6ea45a #include <time.h> for the definition of time functions instead of
depending on namespace pollution 2 layers deep in <sys/stat.h>.

Removed unused includes.
2002-02-25 01:36:59 +00:00
Mark Murray
c73d77cef9 Use __FBSDID() and clean up the vendor tags. 2002-02-03 20:55:54 +00:00
Mark Murray
9052855a15 WARNS=4 fixes, plus a healthy dose of fixes inspired by lint. 2002-02-03 19:11:32 +00:00
Warner Losh
46251dde8f o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
  they already are.
2002-02-02 06:48:10 +00:00