mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2025-09-10 07:59:52 +02:00
ls: add support for explicit file name sorting
Support overriding previous sorting options with an explicit --sort=name option. * doc/coreutils.texi (ls invocation): Document the new option. * src/ls.c (usage): Likewise. (sort_args): Add the "name" entry, and sort to be consistent with the ordering presented in --help. * tests/ls/ls-time.sh: Add test cases. * NEWS: Mention the new feature. Suggested by: Tzvetelin Katchov
This commit is contained in:
5
NEWS
5
NEWS
@@ -32,6 +32,11 @@ GNU coreutils NEWS -*- outline -*-
|
|||||||
stat -f -c%T now reports the "fuseblk" file system type as "fuse",
|
stat -f -c%T now reports the "fuseblk" file system type as "fuse",
|
||||||
given that there is no longer a distinct "ctl" fuse variant file system.
|
given that there is no longer a distinct "ctl" fuse variant file system.
|
||||||
|
|
||||||
|
** New Features
|
||||||
|
|
||||||
|
ls now supports the --sort=name option,
|
||||||
|
to explicitly select the default operation of sorting by file name.
|
||||||
|
|
||||||
** Improvements
|
** Improvements
|
||||||
|
|
||||||
'head -c NUM', 'head -n NUM', 'nl -l NUM', 'nproc --ignore NUM',
|
'head -c NUM', 'head -n NUM', 'nl -l NUM', 'nproc --ignore NUM',
|
||||||
|
|||||||
@@ -8251,6 +8251,13 @@ Sort by version name and number, lowest first. It behaves like a default
|
|||||||
sort, except that each sequence of decimal digits is treated numerically
|
sort, except that each sequence of decimal digits is treated numerically
|
||||||
as an index/version number. @xref{Version sort ordering}.
|
as an index/version number. @xref{Version sort ordering}.
|
||||||
|
|
||||||
|
@item --sort=name
|
||||||
|
@opindex --sort
|
||||||
|
@opindex name@r{, sorting option for @command{ls}}
|
||||||
|
Sort by file name. This is the default operation of @command{ls},
|
||||||
|
and can be explicitly specified to override any
|
||||||
|
previously specified sorting option.
|
||||||
|
|
||||||
@item --sort=width
|
@item --sort=width
|
||||||
@opindex --sort
|
@opindex --sort
|
||||||
@opindex width@r{, sorting option for @command{ls}}
|
@opindex width@r{, sorting option for @command{ls}}
|
||||||
|
|||||||
12
src/ls.c
12
src/ls.c
@@ -911,11 +911,13 @@ ARGMATCH_VERIFY (format_args, format_types);
|
|||||||
|
|
||||||
static char const *const sort_args[] =
|
static char const *const sort_args[] =
|
||||||
{
|
{
|
||||||
"none", "time", "size", "extension", "version", "width", nullptr
|
"none", "size", "time", "version", "extension",
|
||||||
|
"name", "width", nullptr
|
||||||
};
|
};
|
||||||
static enum sort_type const sort_types[] =
|
static enum sort_type const sort_types[] =
|
||||||
{
|
{
|
||||||
sort_none, sort_time, sort_size, sort_extension, sort_version, sort_width
|
sort_none, sort_size, sort_time, sort_version, sort_extension,
|
||||||
|
sort_name, sort_width
|
||||||
};
|
};
|
||||||
ARGMATCH_VERIFY (sort_args, sort_types);
|
ARGMATCH_VERIFY (sort_args, sort_types);
|
||||||
|
|
||||||
@@ -5570,9 +5572,9 @@ Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n\
|
|||||||
-S sort by file size, largest first\n\
|
-S sort by file size, largest first\n\
|
||||||
"), stdout);
|
"), stdout);
|
||||||
fputs (_("\
|
fputs (_("\
|
||||||
--sort=WORD sort by WORD instead of name: none (-U), size (-S)\
|
--sort=WORD change default 'name' sort to WORD:\n\
|
||||||
,\n\
|
none (-U), size (-S), time (-t),\n\
|
||||||
time (-t), version (-v), extension (-X), width\n\
|
version (-v), extension (-X), name, width\n\
|
||||||
\n\
|
\n\
|
||||||
"), stdout);
|
"), stdout);
|
||||||
fputs (_("\
|
fputs (_("\
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ touch -m -d "$t2" B || framework_failure_ # Capital to distinguish name sort
|
|||||||
touch -m -d "$t1" c || framework_failure_
|
touch -m -d "$t1" c || framework_failure_
|
||||||
|
|
||||||
# Check default name sorting works
|
# Check default name sorting works
|
||||||
set $(ls a B c)
|
for def_sort in '' '--sort=name' '-U --sort=name' '--sort-name -t'; do
|
||||||
test "$*" = 'B a c' || fail=1
|
set $(ls $def_sort a B c)
|
||||||
|
test "$*" = 'B a c' || fail=1
|
||||||
|
done
|
||||||
|
|
||||||
touch -a -d "$u3" c || framework_failure_
|
touch -a -d "$u3" c || framework_failure_
|
||||||
touch -a -d "$u2" B || framework_failure_
|
touch -a -d "$u2" B || framework_failure_
|
||||||
|
|||||||
Reference in New Issue
Block a user