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
This commit is contained in:
parent
31d4137bf3
commit
fe79420eb7
26
bin/ls/cmp.c
26
bin/ls/cmp.c
@ -114,6 +114,32 @@ revacccmp(const FTSENT *a, const FTSENT *b)
|
|||||||
return (acccmp(b, a));
|
return (acccmp(b, a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
birthcmp(const FTSENT *a, const FTSENT *b)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (b->fts_statp->st_birthtimespec.tv_sec >
|
||||||
|
a->fts_statp->st_birthtimespec.tv_sec)
|
||||||
|
return (1);
|
||||||
|
if (b->fts_statp->st_birthtimespec.tv_sec <
|
||||||
|
a->fts_statp->st_birthtimespec.tv_sec)
|
||||||
|
return (-1);
|
||||||
|
if (b->fts_statp->st_birthtimespec.tv_nsec >
|
||||||
|
a->fts_statp->st_birthtimespec.tv_nsec)
|
||||||
|
return (1);
|
||||||
|
if (b->fts_statp->st_birthtimespec.tv_nsec <
|
||||||
|
a->fts_statp->st_birthtimespec.tv_nsec)
|
||||||
|
return (-1);
|
||||||
|
return (strcoll(a->fts_name, b->fts_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
revbirthcmp(const FTSENT *a, const FTSENT *b)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (birthcmp(b, a));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
statcmp(const FTSENT *a, const FTSENT *b)
|
statcmp(const FTSENT *a, const FTSENT *b)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
int acccmp(const FTSENT *, const FTSENT *);
|
int acccmp(const FTSENT *, const FTSENT *);
|
||||||
int revacccmp(const FTSENT *, const FTSENT *);
|
int revacccmp(const FTSENT *, const FTSENT *);
|
||||||
|
int birthcmp(const FTSENT *, const FTSENT *);
|
||||||
|
int revbirthcmp(const FTSENT *, const FTSENT *);
|
||||||
int modcmp(const FTSENT *, const FTSENT *);
|
int modcmp(const FTSENT *, const FTSENT *);
|
||||||
int revmodcmp(const FTSENT *, const FTSENT *);
|
int revmodcmp(const FTSENT *, const FTSENT *);
|
||||||
int namecmp(const FTSENT *, const FTSENT *);
|
int namecmp(const FTSENT *, const FTSENT *);
|
||||||
|
@ -149,6 +149,8 @@ When used with the
|
|||||||
.Dq ell )
|
.Dq ell )
|
||||||
option, display complete time information for the file, including
|
option, display complete time information for the file, including
|
||||||
month, day, hour, minute, second, and year.
|
month, day, hour, minute, second, and year.
|
||||||
|
.It Fl U
|
||||||
|
Use time when file was created for sorting or printing.
|
||||||
.It Fl W
|
.It Fl W
|
||||||
Display whiteouts when scanning directories.
|
Display whiteouts when scanning directories.
|
||||||
.It Fl Z
|
.It Fl Z
|
||||||
|
16
bin/ls/ls.c
16
bin/ls/ls.c
@ -104,6 +104,7 @@ int termwidth = 80; /* default terminal width */
|
|||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
int f_accesstime; /* use time of last access */
|
int f_accesstime; /* use time of last access */
|
||||||
|
int f_birthtime; /* use time of birth */
|
||||||
int f_flags; /* show flags associated with a file */
|
int f_flags; /* show flags associated with a file */
|
||||||
int f_humanval; /* show human-readable file sizes */
|
int f_humanval; /* show human-readable file sizes */
|
||||||
int f_inode; /* print inode */
|
int f_inode; /* print inode */
|
||||||
@ -178,7 +179,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
fts_options = FTS_PHYSICAL;
|
fts_options = FTS_PHYSICAL;
|
||||||
while ((ch = getopt(argc, argv,
|
while ((ch = getopt(argc, argv,
|
||||||
"1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
|
"1ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/*
|
/*
|
||||||
* The -1, -C, -x and -l options all override each other so
|
* The -1, -C, -x and -l options all override each other so
|
||||||
@ -207,14 +208,21 @@ main(int argc, char *argv[])
|
|||||||
f_longform = 0;
|
f_longform = 0;
|
||||||
f_singlecol = 0;
|
f_singlecol = 0;
|
||||||
break;
|
break;
|
||||||
/* The -c and -u options override each other. */
|
/* The -c, -u, and -U options override each other. */
|
||||||
case 'c':
|
case 'c':
|
||||||
f_statustime = 1;
|
f_statustime = 1;
|
||||||
f_accesstime = 0;
|
f_accesstime = 0;
|
||||||
|
f_birthtime = 0;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
f_accesstime = 1;
|
f_accesstime = 1;
|
||||||
f_statustime = 0;
|
f_statustime = 0;
|
||||||
|
f_birthtime = 0;
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
f_birthtime = 1;
|
||||||
|
f_accesstime = 0;
|
||||||
|
f_statustime = 0;
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
f_type = 1;
|
f_type = 1;
|
||||||
@ -410,6 +418,8 @@ main(int argc, char *argv[])
|
|||||||
sortfcn = revnamecmp;
|
sortfcn = revnamecmp;
|
||||||
else if (f_accesstime)
|
else if (f_accesstime)
|
||||||
sortfcn = revacccmp;
|
sortfcn = revacccmp;
|
||||||
|
else if (f_birthtime)
|
||||||
|
sortfcn = revbirthcmp;
|
||||||
else if (f_statustime)
|
else if (f_statustime)
|
||||||
sortfcn = revstatcmp;
|
sortfcn = revstatcmp;
|
||||||
else if (f_sizesort)
|
else if (f_sizesort)
|
||||||
@ -421,6 +431,8 @@ main(int argc, char *argv[])
|
|||||||
sortfcn = namecmp;
|
sortfcn = namecmp;
|
||||||
else if (f_accesstime)
|
else if (f_accesstime)
|
||||||
sortfcn = acccmp;
|
sortfcn = acccmp;
|
||||||
|
else if (f_birthtime)
|
||||||
|
sortfcn = birthcmp;
|
||||||
else if (f_statustime)
|
else if (f_statustime)
|
||||||
sortfcn = statcmp;
|
sortfcn = statcmp;
|
||||||
else if (f_sizesort)
|
else if (f_sizesort)
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
extern long blocksize; /* block size units */
|
extern long blocksize; /* block size units */
|
||||||
|
|
||||||
extern int f_accesstime; /* use time of last access */
|
extern int f_accesstime; /* use time of last access */
|
||||||
|
extern int f_birthtime; /* use time of file creation */
|
||||||
extern int f_flags; /* show flags associated with a file */
|
extern int f_flags; /* show flags associated with a file */
|
||||||
extern int f_humanval; /* show human-readable file sizes */
|
extern int f_humanval; /* show human-readable file sizes */
|
||||||
extern int f_label; /* show MAC label */
|
extern int f_label; /* show MAC label */
|
||||||
|
@ -190,6 +190,8 @@ printlong(const DISPLAY *dp)
|
|||||||
printsize(dp->s_size, sp->st_size);
|
printsize(dp->s_size, sp->st_size);
|
||||||
if (f_accesstime)
|
if (f_accesstime)
|
||||||
printtime(sp->st_atime);
|
printtime(sp->st_atime);
|
||||||
|
else if (f_birthtime)
|
||||||
|
printtime(sp->st_birthtime);
|
||||||
else if (f_statustime)
|
else if (f_statustime)
|
||||||
printtime(sp->st_ctime);
|
printtime(sp->st_ctime);
|
||||||
else
|
else
|
||||||
|
@ -222,9 +222,9 @@ usage(void)
|
|||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
#ifdef COLORLS
|
#ifdef COLORLS
|
||||||
"usage: ls [-ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1]"
|
"usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1]"
|
||||||
#else
|
#else
|
||||||
"usage: ls [-ABCFHILPRSTWZabcdfghiklmnopqrstuwx1]"
|
"usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuwx1]"
|
||||||
#endif
|
#endif
|
||||||
" [file ...]\n");
|
" [file ...]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user