aboutsummaryrefslogtreecommitdiff
path: root/bin/ls
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/Makefile3
-rw-r--r--bin/ls/Makefile.depend2
-rw-r--r--bin/ls/Makefile.depend.options1
-rw-r--r--bin/ls/cmp.c23
-rw-r--r--bin/ls/extern.h5
-rw-r--r--bin/ls/ls.175
-rw-r--r--bin/ls/ls.c104
-rw-r--r--bin/ls/ls.h4
-rw-r--r--bin/ls/print.c50
-rw-r--r--bin/ls/tests/Makefile2
-rw-r--r--bin/ls/tests/Makefile.depend1
-rwxr-xr-xbin/ls/tests/ls_tests.sh51
-rw-r--r--bin/ls/util.c12
13 files changed, 211 insertions, 122 deletions
diff --git a/bin/ls/Makefile b/bin/ls/Makefile
index b4076d3a30a1..574ab0d71a45 100644
--- a/bin/ls/Makefile
+++ b/bin/ls/Makefile
@@ -1,6 +1,3 @@
-# @(#)Makefile 8.1 (Berkeley) 6/2/93
-# $FreeBSD$
-
.include <src.opts.mk>
PACKAGE=runtime
diff --git a/bin/ls/Makefile.depend b/bin/ls/Makefile.depend
index bcfa88f57adf..307d2b3370ba 100644
--- a/bin/ls/Makefile.depend
+++ b/bin/ls/Makefile.depend
@@ -1,4 +1,3 @@
-# $FreeBSD$
# Autogenerated - do NOT edit!
DIRDEPS = \
@@ -8,6 +7,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libutil \
+ lib/ncurses/tinfo \
.include <dirdeps.mk>
diff --git a/bin/ls/Makefile.depend.options b/bin/ls/Makefile.depend.options
index 1c27178e9964..b8115550385a 100644
--- a/bin/ls/Makefile.depend.options
+++ b/bin/ls/Makefile.depend.options
@@ -1,4 +1,3 @@
-# $FreeBSD$
# This file is not autogenerated - take care!
DIRDEPS_OPTIONS= LS_COLORS
diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c
index 13ba3ff47a99..4c60506f3456 100644
--- a/bin/ls/cmp.c
+++ b/bin/ls/cmp.c
@@ -32,15 +32,6 @@
* SUCH DAMAGE.
*/
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-
#include <sys/types.h>
#include <sys/stat.h>
@@ -65,6 +56,20 @@ revnamecmp(const FTSENT *a, const FTSENT *b)
}
int
+verscmp(const FTSENT *a, const FTSENT *b)
+{
+
+ return (strverscmp(a->fts_name, b->fts_name));
+}
+
+int
+revverscmp(const FTSENT *a, const FTSENT *b)
+{
+
+ return (strverscmp(b->fts_name, a->fts_name));
+}
+
+int
modcmp(const FTSENT *a, const FTSENT *b)
{
diff --git a/bin/ls/extern.h b/bin/ls/extern.h
index 247c2c4a1d5b..fd9a3f111a47 100644
--- a/bin/ls/extern.h
+++ b/bin/ls/extern.h
@@ -27,9 +27,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * from: @(#)extern.h 8.1 (Berkeley) 5/31/93
- * $FreeBSD$
*/
#include <stdbool.h>
@@ -42,6 +39,8 @@ int modcmp(const FTSENT *, const FTSENT *);
int revmodcmp(const FTSENT *, const FTSENT *);
int namecmp(const FTSENT *, const FTSENT *);
int revnamecmp(const FTSENT *, const FTSENT *);
+int verscmp(const FTSENT *, const FTSENT *);
+int revverscmp(const FTSENT *, const FTSENT *);
int statcmp(const FTSENT *, const FTSENT *);
int revstatcmp(const FTSENT *, const FTSENT *);
int sizecmp(const FTSENT *, const FTSENT *);
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index ef412dd2927d..9621959821be 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -29,10 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
-.\" $FreeBSD$
-.\"
-.Dd August 31, 2020
+.Dd January 16, 2025
.Dt LS 1
.Os
.Sh NAME
@@ -40,8 +37,10 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm
-.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1\&,
+.Op Fl ABCFGHILPRSTUWZabcdfghiklmnopqrstuvwxy1\&,
.Op Fl -color Ns = Ns Ar when
+.Op Fl -group-directories Ns = Ns Ar order
+.Op Fl -group-directories-first
.Op Fl D Ar format
.Op Ar
.Sh DESCRIPTION
@@ -247,9 +246,11 @@ but only if
.Dv stdout
is a tty and either the
.Fl G
-flag is specified or the
+flag is specified or one of the environment variables
.Ev COLORTERM
-environment variable is set and not empty.
+or
+.Ev CLICOLOR
+is set and not empty.
.Pp
.Cm never
will disable color regardless of environment variables.
@@ -301,14 +302,19 @@ and
.Fl s
options.
.It Fl g
-This option has no effect.
-It is only available for compatibility with
-.Bx 4.3 ,
-where it was used to display the group name in the long
+Display the long
.Pq Fl l
-format output.
-This option is incompatible with
-.St -p1003.1-2008 .
+format output without the file owner's name or number.
+.It Fl -group-directories Ns = Ns Ar order
+Within results for each operand,
+group directories together and print them either
+.Cm first
+or
+.Cm last.
+.It Fl -group-directories-first
+Equivalent to
+.Fl -group-directories Ns = Ns Ar first .
+Implemented for compatibility with GNU coreutils.
.It Fl h
When used with the
.Fl l
@@ -399,6 +405,15 @@ of the file for sorting
.Pq Fl t
or printing
.Pq Fl l .
+.It Fl v
+Sort following a natural ordering, using
+.Xr strverscmp 3
+instead of
+.Xr strcoll 3
+as the comparison function.
+E.g., files lexicographically ordered
+"bloem1", "bloem10", and "bloem9" would instead be ordered
+"bloem1", "bloem9", and "bloem10", as one would perhaps expect.
.It Fl w
Force raw printing of non-printable characters.
This is the default
@@ -431,6 +446,8 @@ output is not to a terminal.
.It Fl ,
(Comma) When the
.Fl l
+or
+.Fl s
option is set, print file sizes grouped and separated by thousands using the
non-monetary separator returned by
.Xr localeconv 3 ,
@@ -456,9 +473,9 @@ options all override each other; the last one specified determines
the file time used.
.Pp
The
-.Fl S
+.Fl S , t
and
-.Fl t
+.Fl v
options override each other; the last one specified determines
the sort order used.
.Pp
@@ -534,6 +551,10 @@ which are listed as the directory's contents
and
.Pa ..
and other files which start with a dot, depending on other options).
+If the
+.Fl h
+option is given,
+the total size is displayed as the number of bytes.
.Pp
The default block size is 512 bytes.
The block size may be set with option
@@ -678,7 +699,7 @@ The default
.Dq Li cons25
console has the proper capabilities,
but to display the colors in an
-.Xr xterm 1 ,
+.Xr xterm 1 Pq Pa ports/x11/xterm ,
for example,
the
.Ev TERM
@@ -740,7 +761,7 @@ where
is the foreground color and
.Ar b
is the background color.
-When the background color is capitalized, the text will underlined.
+When the background color is capitalized, the text is underlined.
.Pp
The color designators are as follows:
.Pp
@@ -881,10 +902,12 @@ specification.
.Xr chmod 1 ,
.Xr getfacl 1 ,
.Xr sort 1 ,
-.Xr xterm 1 ,
+.Xr xterm 1 Pq Pa ports/x11/xterm ,
.Xr localeconv 3 ,
+.Xr strcoll 3 ,
.Xr strftime 3 ,
.Xr strmode 3 ,
+.Xr strverscmp 3 ,
.Xr termcap 5 ,
.Xr maclabel 7 ,
.Xr sticky 7 ,
@@ -902,9 +925,14 @@ utility conforms to
and
.St -p1003.1-2008 .
The options
-.Fl B , D , G , I , T , U , W , Z , b , h , w , y
-and
+.Fl B , D , G , I , T , U , W , Z , b , h , v , w , y
+,
.Fl ,
+.Fl -color
+and
+.Fl -group-directories Ns =
+(including
+.Fl -group-directories-first )
are non-standard extensions.
.Pp
The ACL support is compatible with
@@ -918,6 +946,11 @@ An
.Nm
command appeared in
.At v1 .
+.Pp
+The
+.Fl v
+option was added in
+.Fx 13.2 .
.Sh BUGS
To maintain backward compatibility, the relationships between the many
options are quite complex.
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 8a30dd326b4e..b3d0a508d714 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -32,20 +32,6 @@
* SUCH DAMAGE.
*/
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1989, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)ls.c 8.5 (Berkeley) 4/2/94";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@@ -101,12 +87,24 @@ static void display(const FTSENT *, FTSENT *, int);
static int mastercmp(const FTSENT * const *, const FTSENT * const *);
static void traverse(int, char **, int);
-#define COLOR_OPT (CHAR_MAX + 1)
+enum {
+ GRP_NONE = 0,
+ GRP_DIR_FIRST = -1,
+ GRP_DIR_LAST = 1
+};
+
+enum {
+ BIN_OPT = CHAR_MAX,
+ COLOR_OPT,
+ GROUP_OPT
+};
static const struct option long_opts[] =
{
- {"color", optional_argument, NULL, COLOR_OPT},
- {NULL, no_argument, NULL, 0}
+ {"color", optional_argument, NULL, COLOR_OPT},
+ {"group-directories", optional_argument, NULL, GROUP_OPT},
+ {"group-directories-first", no_argument, NULL, GROUP_OPT},
+ {NULL, no_argument, NULL, 0}
};
static void (*printfcn)(const DISPLAY *);
@@ -119,6 +117,7 @@ int termwidth = 80; /* default terminal width */
int f_accesstime; /* use time of last access */
int f_birthtime; /* use time of birth */
int f_flags; /* show flags associated with a file */
+static int f_groupdir = GRP_NONE;/* group directories first/last */
int f_humanval; /* show human-readable file sizes */
int f_inode; /* print inode */
static int f_kblocks; /* print size in kilobytes */
@@ -136,6 +135,7 @@ static int f_numericonly; /* don't convert uid/gid to name */
int f_octal_escape; /* like f_octal but use C escapes if possible */
static int f_recursive; /* ls subdirectories also */
static int f_reversesort; /* reverse whatever sort is used */
+static int f_verssort; /* sort names using strverscmp(3) rather than strcoll(3) */
int f_samesort; /* sort time and name in same direction */
int f_sectime; /* print full time information */
static int f_singlecol; /* use single column output */
@@ -143,6 +143,7 @@ static int f_singlecol; /* use single column output */
static int f_sizesort;
int f_slash; /* similar to f_type, but only for dirs */
int f_sortacross; /* sort across rows, not down columns */
+ int f_sowner; /* disable showing owner's name */
int f_statustime; /* use time of last mode change */
static int f_stream; /* stream the output, separate with commas */
int f_thousands; /* show file sizes with thousands separators */
@@ -275,7 +276,7 @@ main(int argc, char *argv[])
colorflag = COLORFLAG_AUTO;
#endif
while ((ch = getopt_long(argc, argv,
- "+1ABCD:FGHILPRSTUWXZabcdfghiklmnopqrstuwxy,", long_opts,
+ "+1ABCD:FGHILPRSTUWXZabcdfghiklmnopqrstuvwxy,", long_opts,
NULL)) != -1) {
switch (ch) {
/*
@@ -325,14 +326,21 @@ main(int argc, char *argv[])
case 'A':
f_listdot = 1;
break;
- /* The -t and -S options override each other. */
+ /* The -S, -t and -v options override each other. */
case 'S':
f_sizesort = 1;
f_timesort = 0;
+ f_verssort = 0;
break;
case 't':
f_timesort = 1;
f_sizesort = 0;
+ f_verssort = 0;
+ break;
+ case 'v':
+ f_verssort = 1;
+ f_sizesort = 0;
+ f_timesort = 0;
break;
/* Other flags. Please keep alphabetic. */
case ',':
@@ -401,7 +409,11 @@ main(int argc, char *argv[])
f_listdir = 1;
f_recursive = 0;
break;
- case 'g': /* Compatibility with 4.3BSD. */
+ case 'g':
+ f_longform = 1;
+ f_singlecol = 0;
+ f_stream = 0;
+ f_sowner = 1;
break;
case 'h':
f_humanval = 1;
@@ -420,6 +432,9 @@ main(int argc, char *argv[])
break;
case 'n':
f_numericonly = 1;
+ f_longform = 1;
+ f_singlecol = 0;
+ f_stream = 0;
break;
case 'o':
f_flags = 1;
@@ -447,6 +462,15 @@ main(int argc, char *argv[])
case 'y':
f_samesort = 1;
break;
+ case GROUP_OPT:
+ if (optarg == NULL || strcmp(optarg, "first") == 0)
+ f_groupdir = GRP_DIR_FIRST;
+ else if (strcmp(optarg, "last") == 0)
+ f_groupdir = GRP_DIR_LAST;
+ else
+ errx(2, "unsupported --group-directories value '%s' (must be first or last)",
+ optarg);
+ break;
case COLOR_OPT:
#ifdef COLORLS
if (optarg == NULL || do_color_always(optarg))
@@ -523,12 +547,12 @@ main(int argc, char *argv[])
#endif
/*
- * If not -F, -i, -l, -s, -S or -t options, don't require stat
- * information, unless in color mode in which case we do
- * need this to determine which colors to display.
+ * If not -F, -i, -l, -s, -S, -t or --group-directories options,
+ * don't require stat information, unless in color mode in which case
+ * we do need this to determine which colors to display.
*/
if (!f_inode && !f_longform && !f_size && !f_timesort &&
- !f_sizesort && !f_type
+ !f_sizesort && !f_type && f_groupdir == GRP_NONE
#ifdef COLORLS
&& !f_color
#endif
@@ -564,12 +588,15 @@ main(int argc, char *argv[])
blocksize /= 512;
}
}
+
/* Select a sort function. */
if (f_reversesort) {
- if (!f_timesort && !f_sizesort)
- sortfcn = revnamecmp;
- else if (f_sizesort)
+ if (f_sizesort)
sortfcn = revsizecmp;
+ else if (f_verssort)
+ sortfcn = revverscmp;
+ else if (!f_timesort)
+ sortfcn = revnamecmp;
else if (f_accesstime)
sortfcn = revacccmp;
else if (f_birthtime)
@@ -579,10 +606,12 @@ main(int argc, char *argv[])
else /* Use modification time. */
sortfcn = revmodcmp;
} else {
- if (!f_timesort && !f_sizesort)
- sortfcn = namecmp;
- else if (f_sizesort)
+ if (f_sizesort)
sortfcn = sizecmp;
+ else if (f_verssort)
+ sortfcn = verscmp;
+ else if (!f_timesort)
+ sortfcn = namecmp;
else if (f_accesstime)
sortfcn = acccmp;
else if (f_birthtime)
@@ -636,8 +665,10 @@ traverse(int argc, char *argv[], int options)
chp = fts_children(ftsp, 0);
if (chp != NULL)
display(NULL, chp, options);
- if (f_listdir)
+ if (f_listdir) {
+ fts_close(ftsp);
return;
+ }
/*
* If not recursing down this tree and don't need stat info, just get
@@ -686,6 +717,7 @@ traverse(int argc, char *argv[], int options)
}
if (errno)
err(1, "fts_read");
+ fts_close(ftsp);
}
/*
@@ -962,7 +994,8 @@ label_out:
d.maxlen = maxlen;
if (needstats) {
d.btotal = btotal;
- d.s_block = snprintf(NULL, 0, "%lu", howmany(maxblock, blocksize));
+ d.s_block = snprintf(NULL, 0, f_thousands ? "%'ld" : "%ld",
+ howmany(maxblock, blocksize));
d.s_flags = maxflags;
d.s_label = maxlabelstr;
d.s_group = maxgroup;
@@ -993,7 +1026,7 @@ label_out:
static int
mastercmp(const FTSENT * const *a, const FTSENT * const *b)
{
- int a_info, b_info;
+ int a_info, b_info, dir;
a_info = (*a)->fts_info;
if (a_info == FTS_ERR)
@@ -1012,5 +1045,10 @@ mastercmp(const FTSENT * const *a, const FTSENT * const *b)
if (b_info == FTS_D)
return (-1);
}
+
+ if (f_groupdir != GRP_NONE)
+ if ((dir = (a_info == FTS_D) - (b_info == FTS_D)) != 0)
+ return (f_groupdir * dir);
+
return (sortfcn(*a, *b));
}
diff --git a/bin/ls/ls.h b/bin/ls/ls.h
index 410246ec9903..1c3c1cb786f6 100644
--- a/bin/ls/ls.h
+++ b/bin/ls/ls.h
@@ -30,9 +30,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * from: @(#)ls.h 8.1 (Berkeley) 5/31/93
- * $FreeBSD$
*/
#define NO_PRINT 1
@@ -56,6 +53,7 @@ extern int f_sectime; /* print the real time for all files */
extern int f_size; /* list size in short listing */
extern int f_slash; /* append a '/' if the file is a directory */
extern int f_sortacross; /* sort across rows, not down columns */
+extern int f_sowner; /* disable showing the owner's name */
extern int f_statustime; /* use time of last mode change */
extern int f_thousands; /* show file sizes with thousands separators */
extern char *f_timeformat; /* user-specified time format */
diff --git a/bin/ls/print.c b/bin/ls/print.c
index bbe5c6f8a6f6..a504ec63dc26 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -32,14 +32,6 @@
* SUCH DAMAGE.
*/
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/acl.h>
@@ -218,7 +210,14 @@ printlong(const DISPLAY *dp)
if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
(f_longform || f_size)) {
- (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
+ if (!f_humanval)
+ (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
+ else {
+ (void)humanize_number(buf, 7 /* "1024 KB" */,
+ dp->btotal * 512, "B", HN_AUTOSCALE, HN_DECIMAL);
+
+ (void)printf("total %s\n", buf);
+ }
}
for (p = dp->list; p; p = p->fts_link) {
@@ -229,14 +228,16 @@ printlong(const DISPLAY *dp)
(void)printf("%*ju ",
dp->s_inode, (uintmax_t)sp->st_ino);
if (f_size)
- (void)printf("%*jd ",
+ (void)printf(f_thousands ? "%'*jd " : "%*jd ",
dp->s_block, howmany(sp->st_blocks, blocksize));
strmode(sp->st_mode, buf);
aclmode(buf, p);
np = p->fts_pointer;
- (void)printf("%s %*ju %-*s %-*s ", buf, dp->s_nlink,
- (uintmax_t)sp->st_nlink, dp->s_user, np->user, dp->s_group,
- np->group);
+ (void)printf("%s %*ju ", buf, dp->s_nlink,
+ (uintmax_t)sp->st_nlink);
+ if (!f_sowner)
+ (void)printf("%-*s ", dp->s_user, np->user);
+ (void)printf("%-*s ", dp->s_group, np->group);
if (f_flags)
(void)printf("%-*s ", dp->s_flags, np->flags);
if (f_label)
@@ -406,7 +407,7 @@ printaname(const FTSENT *p, u_long inodefield, u_long sizefield)
chcnt += printf("%*ju ",
(int)inodefield, (uintmax_t)sp->st_ino);
if (f_size)
- chcnt += printf("%*jd ",
+ chcnt += printf(f_thousands ? "%'*jd " : "%*jd ",
(int)sizefield, howmany(sp->st_blocks, blocksize));
#ifdef COLORLS
if (f_color)
@@ -432,18 +433,17 @@ printdev(size_t width, dev_t dev)
(void)printf("%#*jx ", (u_int)width, (uintmax_t)dev);
}
-static size_t
+static void
ls_strftime(char *str, size_t len, const char *fmt, const struct tm *tm)
{
char *posb, nfmt[BUFSIZ];
const char *format = fmt;
- size_t ret;
if ((posb = strstr(fmt, "%b")) != NULL) {
if (month_max_size == 0) {
compute_abbreviated_month_size();
}
- if (month_max_size > 0) {
+ if (month_max_size > 0 && tm != NULL) {
snprintf(nfmt, sizeof(nfmt), "%.*s%s%*s%s",
(int)(posb - fmt), fmt,
get_abmon(tm->tm_mon),
@@ -453,8 +453,10 @@ ls_strftime(char *str, size_t len, const char *fmt, const struct tm *tm)
format = nfmt;
}
}
- ret = strftime(str, len, format, tm);
- return (ret);
+ if (tm != NULL)
+ strftime(str, len, format, tm);
+ else
+ strlcpy(str, "bad date val", len);
}
static void
@@ -758,12 +760,10 @@ printsize(size_t width, off_t bytes)
humanize_number(buf, sizeof(buf), (int64_t)bytes, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
(void)printf("%*s ", (u_int)width, buf);
- } else if (f_thousands) { /* with commas */
- /* This format assignment needed to work round gcc bug. */
- const char *format = "%*j'd ";
- (void)printf(format, (u_int)width, bytes);
- } else
- (void)printf("%*jd ", (u_int)width, bytes);
+ } else {
+ (void)printf(f_thousands ? "%'*jd " : "%*jd ",
+ (u_int)width, bytes);
+ }
}
/*
diff --git a/bin/ls/tests/Makefile b/bin/ls/tests/Makefile
index 89a2e8cf1dca..e750910cc91d 100644
--- a/bin/ls/tests/Makefile
+++ b/bin/ls/tests/Makefile
@@ -1,5 +1,3 @@
-# $FreeBSD$
-
ATF_TESTS_SH+= ls_tests
# This seems like overkill, but the idea in mind is that all of the testcases
# should be runnable as !root
diff --git a/bin/ls/tests/Makefile.depend b/bin/ls/tests/Makefile.depend
index f80275d86ab1..11aba52f82cf 100644
--- a/bin/ls/tests/Makefile.depend
+++ b/bin/ls/tests/Makefile.depend
@@ -1,4 +1,3 @@
-# $FreeBSD$
# Autogenerated - do NOT edit!
DIRDEPS = \
diff --git a/bin/ls/tests/ls_tests.sh b/bin/ls/tests/ls_tests.sh
index 14f7895e699c..c732b60b21a4 100755
--- a/bin/ls/tests/ls_tests.sh
+++ b/bin/ls/tests/ls_tests.sh
@@ -24,7 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-# $FreeBSD$
#
create_test_dir()
@@ -525,18 +524,19 @@ f_flag_body()
atf_test_case g_flag
g_flag_head()
{
- atf_set "descr" "Verify that -g does nothing (compatibility flag)"
+ atf_set "descr" "Verify that -g implies -l but omits the owner name field"
}
g_flag_body()
{
- create_test_inputs2
- for file in $files; do
- atf_check -e empty -o match:"$(ls -a $file)" -s exit:0 \
- ls -ag $file
- atf_check -e empty -o match:"$(ls -la $file)" -s exit:0 \
- ls -alg $file
- done
+ atf_check -e empty -o empty -s exit:0 touch a.file
+
+ mtime_in_secs=$(stat -f "%m" -t "%s" a.file)
+ mtime=$(date -j -f "%s" $mtime_in_secs +"%b[[:space:]]+%e[[:space:]]+%H:%M")
+
+ expected_output=$(stat -f "%Sp[[:space:]]+%l[[:space:]]+%Sg[[:space:]]+%z[[:space:]]+$mtime[[:space:]]+a\\.file" a.file)
+
+ atf_check -e empty -o match:"$expected_output" -s exit:0 ls -g a.file
}
atf_test_case h_flag
@@ -689,7 +689,7 @@ n_flag_body()
atf_check -e empty \
-o match:'\-rw\-r\-\-r\-\-[[:space:]]+1[[:space:]]+'"$nobody_uid[[:space:]]+$daemon_gid"'[[:space:]]+.+a\.file' \
- ls -ln a.file
+ ls -n a.file
}
@@ -800,6 +800,21 @@ s_flag_body()
done
}
+atf_test_case scomma_flag
+scomma_flag_head()
+{
+ atf_set "descr" "Verify that -s, prints out the size with ',' delimiters"
+}
+
+scomma_flag_body()
+{
+ export LC_ALL=en_US.UTF-8
+ atf_check -e ignore dd if=/dev/urandom of=file bs=65536 count=64
+ blocks=$(stat -f "%b" file)
+ cblocks=$(printf "%'d" $blocks)
+ atf_check -e empty -o match:"$cblocks[[:space:]]+file" ls -s, file
+}
+
atf_test_case t_flag
t_flag_head()
{
@@ -846,6 +861,20 @@ u_flag_body()
atf_check -e empty -o match:'a\.file.*b\.file' -s exit:0 ls -Cu
}
+atf_test_case v_flag
+v_flag_head()
+{
+ atf_set "descr" "Verify that the output from ls -v sorts based on strverscmp(3)"
+}
+
+v_flag_body()
+{
+ create_test_dir
+
+ atf_check -e empty -o empty -s exit:0 touch 000 00 01 010 09 0 1 9 10
+ atf_check -e empty -o match:"000.00.01.010.09.0.1.9.10" -s exit:0 sh -c 'ls -Cv'
+}
+
atf_test_case x_flag
x_flag_head()
{
@@ -958,8 +987,10 @@ atf_init_test_cases()
atf_add_test_case q_flag_and_w_flag
atf_add_test_case r_flag
atf_add_test_case s_flag
+ atf_add_test_case scomma_flag
atf_add_test_case t_flag
atf_add_test_case u_flag
+ atf_add_test_case v_flag
atf_add_test_case x_flag
atf_add_test_case y_flag
atf_add_test_case 1_flag
diff --git a/bin/ls/util.c b/bin/ls/util.c
index 44012de58bba..d83cae0e98d1 100644
--- a/bin/ls/util.c
+++ b/bin/ls/util.c
@@ -32,14 +32,6 @@
* SUCH DAMAGE.
*/
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94";
-#endif /* not lint */
-#endif
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/stat.h>
@@ -227,9 +219,9 @@ usage(void)
{
(void)fprintf(stderr,
#ifdef COLORLS
- "usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [--color=when] [-D format]"
+ "usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuvwxy1,] [--color=when] [-D format] [--group-directories=]"
#else
- "usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format]"
+ "usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuvwxy1,] [-D format] [--group-directories=]"
#endif
" [file ...]\n");
exit(1);