ls: add -f and -S options
This commit is contained in:
parent
787d99d896
commit
9fdef90feb
2
README
2
README
|
@ -42,7 +42,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
||||||
=*| ln yes none
|
=*| ln yes none
|
||||||
=*| logger yes none
|
=*| logger yes none
|
||||||
=*| logname yes none
|
=*| logname yes none
|
||||||
# ls no (-C), -S, -f, (-m), (-s), (-x)
|
#* ls no (-C), (-m), (-s), (-x)
|
||||||
=*| md5sum non-posix none
|
=*| md5sum non-posix none
|
||||||
=*| mkdir yes none
|
=*| mkdir yes none
|
||||||
=*| mkfifo yes none
|
=*| mkfifo yes none
|
||||||
|
|
16
ls.1
16
ls.1
|
@ -1,4 +1,4 @@
|
||||||
.Dd February 21, 2015
|
.Dd March 18, 2015
|
||||||
.Dt LS 1
|
.Dt LS 1
|
||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -6,7 +6,7 @@
|
||||||
.Nd list directory contents
|
.Nd list directory contents
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl 1AacdFHhiLlnqrtUu
|
.Op Fl 1AacdFfHhiLlnqrStUu
|
||||||
.Op Ar file ...
|
.Op Ar file ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
|
@ -25,6 +25,16 @@ modification time for sorting or printing.
|
||||||
List directories themselves, not their contents.
|
List directories themselves, not their contents.
|
||||||
.It Fl F
|
.It Fl F
|
||||||
Append a file type indicator to all special files.
|
Append a file type indicator to all special files.
|
||||||
|
.It Fl f
|
||||||
|
Like
|
||||||
|
.Fl U
|
||||||
|
but turns on
|
||||||
|
.Fl a
|
||||||
|
and disables
|
||||||
|
.Fl r ,
|
||||||
|
.Fl S
|
||||||
|
and
|
||||||
|
.Fl t .
|
||||||
.It Fl H
|
.It Fl H
|
||||||
List information about the targets of symbolic links specified on the command
|
List information about the targets of symbolic links specified on the command
|
||||||
line instead of the links themselves.
|
line instead of the links themselves.
|
||||||
|
@ -52,6 +62,8 @@ List directory content recursively. The
|
||||||
flag is set implicitly.
|
flag is set implicitly.
|
||||||
.It Fl r
|
.It Fl r
|
||||||
Reverse the sort order.
|
Reverse the sort order.
|
||||||
|
.It Fl S
|
||||||
|
Sort files by size (in decreasing order).
|
||||||
.It Fl t
|
.It Fl t
|
||||||
Sort files by last file status/modification time instead of by name.
|
Sort files by last file status/modification time instead of by name.
|
||||||
.It Fl U
|
.It Fl U
|
||||||
|
|
24
ls.c
24
ls.c
|
@ -29,6 +29,7 @@ static int aflag = 0;
|
||||||
static int cflag = 0;
|
static int cflag = 0;
|
||||||
static int dflag = 0;
|
static int dflag = 0;
|
||||||
static int Fflag = 0;
|
static int Fflag = 0;
|
||||||
|
static int fflag = 0;
|
||||||
static int Hflag = 0;
|
static int Hflag = 0;
|
||||||
static int hflag = 0;
|
static int hflag = 0;
|
||||||
static int iflag = 0;
|
static int iflag = 0;
|
||||||
|
@ -38,6 +39,7 @@ static int nflag = 0;
|
||||||
static int pflag = 0;
|
static int pflag = 0;
|
||||||
static int qflag = 0;
|
static int qflag = 0;
|
||||||
static int Rflag = 0;
|
static int Rflag = 0;
|
||||||
|
static int Sflag = 0;
|
||||||
static int rflag = 0;
|
static int rflag = 0;
|
||||||
static int tflag = 0;
|
static int tflag = 0;
|
||||||
static int Uflag = 0;
|
static int Uflag = 0;
|
||||||
|
@ -176,12 +178,15 @@ output(const struct entry *ent)
|
||||||
static int
|
static int
|
||||||
entcmp(const void *va, const void *vb)
|
entcmp(const void *va, const void *vb)
|
||||||
{
|
{
|
||||||
|
int cmp = 0;
|
||||||
const struct entry *a = va, *b = vb;
|
const struct entry *a = va, *b = vb;
|
||||||
|
|
||||||
if (tflag)
|
if (Sflag)
|
||||||
return b->t - a->t;
|
cmp = b->size - a->size;
|
||||||
else
|
else if (tflag)
|
||||||
return strcmp(a->name, b->name);
|
cmp = b->t - a->t;
|
||||||
|
|
||||||
|
return cmp ? cmp : strcmp(a->name, b->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -289,6 +294,11 @@ main(int argc, char *argv[])
|
||||||
case 'd':
|
case 'd':
|
||||||
dflag = 1;
|
dflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
aflag = 1;
|
||||||
|
fflag = 1;
|
||||||
|
Uflag = 1;
|
||||||
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
Fflag = 1;
|
Fflag = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -321,9 +331,15 @@ main(int argc, char *argv[])
|
||||||
Rflag = 1;
|
Rflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
|
if (!fflag)
|
||||||
rflag = 1;
|
rflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
Sflag = 1;
|
||||||
|
tflag = 0;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
|
Sflag = 0;
|
||||||
tflag = 1;
|
tflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user