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 Dec 26 21:03:49 2004  
Votes:  105  
Category: NonePriority: 5 - Normal
Status: Ready For TestPrivacy: Public
Assigned to: NoneOriginator Email: -unavailable-
Open/Closed: Open

(Jump to the original submission Jump to the original submission)

Thu Dec 14 11:28:32 2006, 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 Apr 30 02:47:17 2006, 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 Dec 10 10:19:42 2005, 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 Dec 9 20:19:17 2005, 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 Dec 9 11:38:17 2005, 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 Dec 5 14:04:18 2005, 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 Dec 26 21:03:49 2004, 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 (1kB - 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 (5kB - text/x-patch)
file #8207:  coreutils-5.2.1-ls.patch added by None (2kB - 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
  • -unavailable- added by mikelward (Voted in favor of this item)
  • -unavailable- added by lebert (Updated the item)

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

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 9 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed Aug 17 19:29:15 2011mikelwardCarbon-Copy-=>Added mikelward
    Thu Dec 14 11:28:32 2006lebertAttached File-=>Added ls_--group-directories-first_symlinks_to_dir_are_dirs_too.patch, #11524
    Sun Apr 30 02:47:17 2006ericbStatusNone=>Ready For Test
    Tue Dec 27 18:41:49 2005frmAttached File-=>Added changelog.patch, #5665
    Sat Dec 10 10:19:42 2005frmAttached File-=>Added doc.patch, #5571
    Fri Dec 9 20:19:17 2005frmAttached File-=>Added ls-group-dirs.patch, #5570
    Fri Dec 9 11:38:17 2005frmCarbon-Copy-=>Added -unavailable-
    Fri Dec 9 11:36:22 2005frmCarbon-Copy-=>Added frm
    Sun Dec 26 21:03:49 2004NoneAttached File-=>Added coreutils-5.2.1-ls.patch, #3974

    Back to the top

    Powered by Savane 3.1-cleanup1