sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 7264acf7edaa2e90105b9220f500e3d596b5c552
parent 9e37634571799f8525bb36749975e5739461ff78
Author: Quentin Rameau <quinq@quinq.eu.org>
Date:   Sun, 22 Feb 2015 12:55:38 +0100

ls: add -n option

Diffstat:
MREADME | 2+-
Mls.1 | 6+++++-
Mls.c | 12++++++++----
3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/README b/README @@ -41,7 +41,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support, =* ln yes none =* logger yes none =* logname yes none -= ls no (-C), -S, -f, -m, -n, -s, -x += ls no (-C), -S, -f, -m, -s, -x =* md5sum non-posix none =* mkdir yes none =* mkfifo yes none diff --git a/ls.1 b/ls.1 @@ -6,7 +6,7 @@ .Nd list directory contents .Sh SYNOPSIS .Nm -.Op Fl 1AacdFHhiLlqrtUu +.Op Fl 1AacdFHhiLlnqrtUu .Op Ar file ... .Sh DESCRIPTION .Nm @@ -38,6 +38,10 @@ themselves. .It Fl l List detailed information about each file, including their type, permissions, links, owner, group, size, and last file status/modification time. +.It Fl n +List detailed information about each file, including their type, permissions, +links, owner, group, size, and last file status/modification time, but with +numeric IDs. .It Fl p Append a file type indicator to directories. .It Fl q diff --git a/ls.c b/ls.c @@ -34,6 +34,7 @@ static int hflag = 0; static int iflag = 0; static int Lflag = 0; static int lflag = 0; +static int nflag = 0; static int pflag = 0; static int qflag = 0; static int Rflag = 0; @@ -140,14 +141,12 @@ output(const struct entry *ent) if (ent->mode & S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S'; if (ent->mode & S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T'; - pw = getpwuid(ent->uid); - if (pw) + if (!nflag && (pw = getpwuid(ent->uid))) snprintf(pwname, LEN(pwname), "%s", pw->pw_name); else snprintf(pwname, LEN(pwname), "%d", ent->uid); - gr = getgrgid(ent->gid); - if (gr) + if (!nflag && (gr = getgrgid(ent->gid))) snprintf(grname, LEN(grname), "%s", gr->gr_name); else snprintf(grname, LEN(grname), "%d", ent->gid); @@ -159,6 +158,7 @@ output(const struct entry *ent) strftime(buf, sizeof(buf), fmt, localtime(&ent->t)); printf("%s %4ld %-8.8s %-8.8s ", mode, (long)ent->nlink, pwname, grname); + if (hflag) printf("%10s ", humansize((unsigned long)ent->size)); else @@ -307,6 +307,10 @@ main(int argc, char *argv[]) case 'l': lflag = 1; break; + case 'n': + lflag = 1; + nflag = 1; + break; case 'p': pflag = 1; break;