On bash, this will sort of work:
$ ls | rev | sort | rev
From man rev
:
The rev utility copies the specified files to the standard output,
reversing the order of characters in every line. If no files are speci-
fied, the standard input is read.
So
1. ls gives its output, with any flags you want
2. each line is reversed
3. then they're sorted
4. and reversed again
5. like this:
- like this:
- each line is reversed
- then they're sorted
- and reversed again
So
- ls gives its output, with any flags you want
Or, more to the point, as below. They're sorted by last character, then next-to-last, etc. All the .rtf files, for example, are listed together, after a .save file and another file with no extension whose name ends in 'e'. Then come .png files, and so on. This will also work with ls -l, because the extension is normally the last thing on the line (exceptions if you have lines like "tmp@ -> /home/jones/tmp", where links are followed by their targets).
$ ls | rev|sort|rev
cslu1
ls.mp2
ls.mp3
ls.mp4
trees_110214-15
PAT
CSLU
Proxy Form.doc
finannbyid
toannbyid
101209ssi.txt.save
to_annotate_size
Matas-time-by-week-integration2.rtf
cyp3.rtf
data-dir-scan.perl.doc.rtf
whence-r21-numid.rtf
platypus.rtf
Screen shot 2011-01-21 at 2.17.50 PM.png
emacs print help.png
log
new_month_log
special
Google-ngram-critique.html
perl_path.html
nl
DWE_BEN_89808.2.ann
foo
d.o.foo
100811_from_iMac_Documents_in_dock.zip
to-palikir.zip
tmp
file-cleanup
bar
data-scan-docs
cmp-mg-ann-numids
finished_numids
to_annotate_numids
manls.ps
Mike_address_ticket
cyp2.out
cyp3.out
locate-cyp.out
manls.out
DWE_BEN_89808.2.text
tag2.txt
l2.txt
du-h-d3.txt
finished_ann_numids_110407_1714.txt
finished_all_numids_110407_1718.txt
data-dir-scan.perl.doc.txt
whence-r21-numid.txt
finannid.txt
toannid.txt
b9-workspace-anndiff.txt
tag.txt
duh.txt
d.o-mail.txt
safextn.txt
mg3longhdr.txt
finished_numids.txt
41692-langnames.txt
TimeAnnotationGuidelines.txt
41langs.txt
thing4-homedir-links.txt
bnlinks.txt
grants.txt
mata-file-reports.txt
logx.txt
logx
b9-workspace-anndiff.txt~
bnlinks.txt~
Yes no problem combining
-X / --sort=extension
with--group-directories-first
and anything else I've tried on modern Linux distros. The OP is referring to Fedora Core 8 (released 2007) so chances are any such problems are in the distant past. – mattst – 2019-03-08T20:42:46.9475I know this post is rather old, but to others coming here from e.g. Google (like I did): The combination of
--sort=extension
and--group-directories-first
(or only--group-directories
) works fine for me on Ubuntu 12.10. Worth a shot on your machine too! =) – Tomas Aschan – 2013-03-29T11:27:28.367