summaryrefslogtreecommitdiffstats
path: root/bin/ls
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-03-24 16:38:02 +0000
committerjhb <jhb@FreeBSD.org>2006-03-24 16:38:02 +0000
commit3d92b82bd8ba73b42a6a9ac9a402858ba7562172 (patch)
tree7e29299b116232736273c0ea1c22bfb2ba2ba8de /bin/ls
parent0f0a98fed88d1f3b6c70ffa9b1ce7142f85e8e78 (diff)
downloadFreeBSD-src-3d92b82bd8ba73b42a6a9ac9a402858ba7562172.zip
FreeBSD-src-3d92b82bd8ba73b42a6a9ac9a402858ba7562172.tar.gz
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
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/cmp.c26
-rw-r--r--bin/ls/extern.h2
-rw-r--r--bin/ls/ls.12
-rw-r--r--bin/ls/ls.c16
-rw-r--r--bin/ls/ls.h1
-rw-r--r--bin/ls/print.c2
-rw-r--r--bin/ls/util.c4
7 files changed, 49 insertions, 4 deletions
diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c
index 37b4a75..badd108 100644
--- a/bin/ls/cmp.c
+++ b/bin/ls/cmp.c
@@ -115,6 +115,32 @@ revacccmp(const FTSENT *a, const FTSENT *b)
}
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)
{
diff --git a/bin/ls/extern.h b/bin/ls/extern.h
index 02a61f5..f290fbb 100644
--- a/bin/ls/extern.h
+++ b/bin/ls/extern.h
@@ -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 *);
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 4a16679..ce4c65e 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -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
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index f354fc2..4a752ce 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -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)
diff --git a/bin/ls/ls.h b/bin/ls/ls.h
index d4e5db6..4d12b22 100644
--- a/bin/ls/ls.h
+++ b/bin/ls/ls.h
@@ -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 */
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 185b418..8ca40e2 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -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
diff --git a/bin/ls/util.c b/bin/ls/util.c
index 01ae6cb..62fa75a 100644
--- a/bin/ls/util.c
+++ b/bin/ls/util.c
@@ -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);
OpenPOWER on IntegriCloud