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:
John Baldwin 2006-03-24 16:38:02 +00:00
parent 31d4137bf3
commit fe79420eb7
7 changed files with 49 additions and 4 deletions

View File

@ -114,6 +114,32 @@ revacccmp(const FTSENT *a, const FTSENT *b)
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
statcmp(const FTSENT *a, const FTSENT *b)
{

View File

@ -32,6 +32,8 @@
int acccmp(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 revmodcmp(const FTSENT *, const FTSENT *);
int namecmp(const FTSENT *, const FTSENT *);

View File

@ -149,6 +149,8 @@ When used with the
.Dq ell )
option, display complete time information for the file, including
month, day, hour, minute, second, and year.
.It Fl U
Use time when file was created for sorting or printing.
.It Fl W
Display whiteouts when scanning directories.
.It Fl Z

View File

@ -104,6 +104,7 @@ int termwidth = 80; /* default terminal width */
/* flags */
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_humanval; /* show human-readable file sizes */
int f_inode; /* print inode */
@ -178,7 +179,7 @@ main(int argc, char *argv[])
fts_options = FTS_PHYSICAL;
while ((ch = getopt(argc, argv,
"1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
"1ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx")) != -1) {
switch (ch) {
/*
* 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_singlecol = 0;
break;
/* The -c and -u options override each other. */
/* The -c, -u, and -U options override each other. */
case 'c':
f_statustime = 1;
f_accesstime = 0;
f_birthtime = 0;
break;
case 'u':
f_accesstime = 1;
f_statustime = 0;
f_birthtime = 0;
break;
case 'U':
f_birthtime = 1;
f_accesstime = 0;
f_statustime = 0;
break;
case 'F':
f_type = 1;
@ -410,6 +418,8 @@ main(int argc, char *argv[])
sortfcn = revnamecmp;
else if (f_accesstime)
sortfcn = revacccmp;
else if (f_birthtime)
sortfcn = revbirthcmp;
else if (f_statustime)
sortfcn = revstatcmp;
else if (f_sizesort)
@ -421,6 +431,8 @@ main(int argc, char *argv[])
sortfcn = namecmp;
else if (f_accesstime)
sortfcn = acccmp;
else if (f_birthtime)
sortfcn = birthcmp;
else if (f_statustime)
sortfcn = statcmp;
else if (f_sizesort)

View File

@ -38,6 +38,7 @@
extern long blocksize; /* block size units */
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_humanval; /* show human-readable file sizes */
extern int f_label; /* show MAC label */

View File

@ -190,6 +190,8 @@ printlong(const DISPLAY *dp)
printsize(dp->s_size, sp->st_size);
if (f_accesstime)
printtime(sp->st_atime);
else if (f_birthtime)
printtime(sp->st_birthtime);
else if (f_statustime)
printtime(sp->st_ctime);
else

View File

@ -222,9 +222,9 @@ usage(void)
{
(void)fprintf(stderr,
#ifdef COLORLS
"usage: ls [-ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1]"
"usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1]"
#else
"usage: ls [-ABCFHILPRSTWZabcdfghiklmnopqrstuwx1]"
"usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuwx1]"
#endif
" [file ...]\n");
exit(1);