patchGNU Core Utilities - Patches: patch #3596, Sort directories before files in...


You are not allowed to post comments on this tracker with your current authentication level.

patch #3596: Sort directories before files in "ls"

Submitted by:  None
Submitted on:  Sun 26 Dec 2004 09:03:49 PM UTC  
Votes:  105  
Category:  None Priority:  5 - Normal
Status:  Ready For Test Privacy:  Public
Assigned to:  None Originator Email:  -email is unavailable-
Open/Closed:  Open

( Jump to the original submission)

Thu 14 Dec 2006 11:28:32 AM UTC, comment #6: 

This is an enhancement for the actual implementation for the '--group-directories-first' option in ls, so that symbolic links to directories are handled as directories with this option enabled.

(file #11524)

Bert Wesarg <lebert>
Sun 30 Apr 2006 02:47:17 AM UTC, comment #5: 

A derivative of the ideas in this patch tracker has been committed to CVS this week, so in coreutils 6.0, you will be able to do 'ls --group-directories-first'.  Burning another short option letter (such as the suggested -e) was deemed inappropriate for ls, which already has more than its fair share of short options.

Eric Blake <ericb>
Project Administrator
Sat 10 Dec 2005 10:19:42 AM UTC, comment #4: 

PS: a couple of things I forgot:
1) I added another small patch which modifies also the coreutils.texi file
2) I assign the copyright to the FSF for all my patches submitted in this tracker

Francesco Montorsi <frm>
Fri 09 Dec 2005 08:19:17 PM UTC, comment #3: 

I've added to this tracker a new patch which should address all issues raised by Eric Blake.

The only thing left out are systems without dirent.d_type: a stat for each file isn't going to be too slow ?
Maybe that for those systems without dirent.d_type, it's better to just not implement this option....

Please let me know if something needs to be changed.

NOTE1: symlinks to directories are treated as simple files.

NOTE2: I couldn't think of any long option which begins with an unused char; so I have used the -e option together with the long option --group-directories

Francesco Montorsi <frm>
Fri 09 Dec 2005 11:38:17 AM UTC, comment #2: 

If the original patch author doesn't mind, I'll try to make the changes suggested by Eric Blake and then make a new patch.
I'll let you know.

Francesco Montorsi <frm>
Mon 05 Dec 2005 02:04:18 PM UTC, comment #1: 

Several problems with the proposed patch:

No ChangeLog.  Also, your patch is incomplete without also touching NEWS and doc/coreutils.texi, not to mention updating the testsuite.

It is big enough that you would need to assign copyright to the FSF before we can consider it.

You did not add a corresponding long option for -e; and -e does not really have a good mneumonic to imply what it is doing (although -d and -D are already taken for --directories-first, and -g and -G are already taken for --group-directories-first.  It would be nice if the long option could start with the same letter as the proposed short option).

Your proposed patch treats directory sorts as equal with all other sorts, meaning that there is no way to group directories first, but then sort directories by size and files by size.  I envision this feature as independent from --sort, that when it is enabled, directories are always sorted first, but that then the two groups (dirs and non-dirs) can be additionally sorted by whatever --sort option is in effect.  That also means that in a --reverse sort, I think directories should still be listed first, not last.

Your patch does not take into account the fact that on systems without dirent.d_type, you will need to stat every file to ensure which files are directories before you can meaningfully group directories first.

Your patch does not take into account what behavior should be used with symlinks to dirs - are they grouped with directories, or with files, or does it depend on other options (such as -L)?

Eric Blake <ericb>
Project Administrator
Sun 26 Dec 2004 09:03:49 PM UTC, original submission:  

Added new option "-e" to ls to sort directories before sorting files. e.g:

[22:02][lurch]$ /bin/ls -l
total 8
drwxr-xr-x  2 lurch users 4096 Dec 26 22:02 a
-rw-r--r--  1 lurch users    0 Dec 26 22:02 b
drwxr-xr-x  2 lurch users 4096 Dec 26 22:02 c
-rw-r--r--  1 lurch users    0 Dec 26 22:02 e
[22:02][lurch]$ /bin/ls -le
total 8
drwxr-xr-x  2 lurch users 4096 Dec 26 22:02 a
drwxr-xr-x  2 lurch users 4096 Dec 26 22:02 c
-rw-r--r--  1 lurch users    0 Dec 26 22:02 b
-rw-r--r--  1 lurch users    0 Dec 26 22:02 e



Attached Files
file #11524:  ls_--group-directories-first_symlinks_to_dir_are_dirs_too.patch added by lebert (1KiB - text/x-patch - handle symlinks to dirs as dirs in option --group-directories-first)
file #9058:  changelog.patch added by frm (960B - text/x-patch - Changelog patch)
file #4136:  doc.patch added by frm (687B - text/x-patch - This one really needs testing as I don't know the Tex language ;))
file #4135:  ls-group-dirs.patch added by frm (5KiB - text/x-patch)
file #8207:  coreutils-5.2.1-ls.patch added by None (2KiB - application/octet-stream - Add "-e" option to ls to sort directories before files)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by mikelward (Voted in favor of this item)
  • -email is unavailable- added by lebert (Updated the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 105 encouragements so far.

    Only logged-in users can vote.




    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-08-17 mikelward Carbon-Copy- => Added mikelward
    2006-12-14 lebert Attached File- => Added ls_--group-directories-first_symlinks_to_dir_are_dirs_too.patch, #11524
    2006-04-30 ericb StatusNone => Ready For Test
    2005-12-27 frm Attached File- => Added changelog.patch, #5665
    2005-12-10 frm Attached File- => Added doc.patch, #5571
    2005-12-09 frm Attached File- => Added ls-group-dirs.patch, #5570
    2005-12-09 frm Carbon-Copy- => Added
    2005-12-09 frm Carbon-Copy- => Added frm
    2004-12-26 None Attached File- => Added coreutils-5.2.1-ls.patch, #3974

    Back to the top

    Powered by Savane 3.5