Bug 153120

Summary: ls output needs more control and is too limited
Product: [Fedora] Fedora Reporter: Brian "netdragon" Bober <netdragon>
Component: coreutilsAssignee: Tim Waugh <twaugh>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: rawhide   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-04-01 13:56:40 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Brian "netdragon" Bober 2005-04-01 13:12:08 EST
Description of problem:

I would like to propose and additional parameter for ls that would give a lot
more control. The parameter would be --printf (like in printf find) or something
like that, and would let you specify what columns you want to see.

There are issues with the parameters for ls. The main issue is that you cannot
properly individually specify which columns of ls -l you need, which means you
have to use some regexp magic with a stream editor, which is not very efficient
and hard to remember how to do. It's also not good for people migrating from
other platforms. There are a huge mess of hard-to-remember modifiers

To give an example of the mess:
ls -l shows:
drwxr-xr-x  22 root root     4096 Apr  1 02:23 var

To remove the user name, ls -g:
drwxr-xr-x  22 root     4096 Apr  1 02:23 var

To remove both user and group ls -gG
drwxr-xr-x  22     4096 Apr  1 02:23 var

Big issues:
1) We can't (afaik) remove time from the -l listing.
2) We can't (afaik) individually show file size, since the -s parameter shows
disk space usage and doesn't even match the file size which is shown in -l (if
you use --block-size=1)
3) We have to use the find `pwd` in order to show the full file path, because ls
doesn't allow you to show bare output with full pathnames. Instead, it prints
the directory name, then the files that are contained.

First of all, we need a replacement for -s that shows the actual size of file,
not disk space used. Perhaps --actualsize, and we need a parameter to remove any
field from -l (or better yet, specify fields)

But we need also a parameter to give us more control on placement...

I suggest we have a --printf parameter that you use formatting characters, such
as (but not necessarily) %%%f to show the filename only, %%%[n.m]b to show the
full path of the file, %%%[n.m]c to show the files' path relative to the current
directory. n and m would be optional and would tell how many portions of the
path to remove from the beginning and end of the output (0 for either does
nothing) %%%t for time, %%%u for user, %%%s for actual size, and %%%y for number
of blocks used on disk (like -s), etc... It'd look like:
user@server ~ ls --printf "%%%c %%%1.c %%%2.b %%%1.b %%%b %%%.1b %%%f %%%s fdsa
fdsa %%%u" \ blah/foo.txt

./blah/foo.txt blah/foo.txt user/blah/foo.txt home/user/foo.txt
/home/user/foo.txt /home/user foo.txt 543 fdsa fdsa user

I chose %%% simply because it wouldn't confuse people over other definitions for
Comment 1 Brian "netdragon" Bober 2005-04-01 13:56:40 EST
Forget the printf parameter because find has it (though it'd be nice to have
more control over stipping directories) -- I'll file a new bug about ls needing
a proper -s parameter.