If you're not particular about the ordering of the special characters, then zsh
's numeric sorting glob qualifier gets close:
Setup
$ touch "Ie5" "Ie6" "Ie4 01" 'Ie4!01' "Ie4_01" "Ie4_128" "Ie401sp2" "Ie501sp2"
$ mkdir Foo Quux Ie7bar
zsh only
$ print -l *(n/) *(n^/)
Foo
Ie7bar
Quux
Ie4 01
Ie4_01
Ie4!01
Ie4_128
Ie5
Ie6
Ie401sp2
Ie501sp2
with ls
$ ls -1df *(n/) *(n^/)
Foo
Ie7bar
Quux
Ie4 01
Ie4_01
Ie4!01
Ie4_128
Ie5
Ie6
Ie401sp2
Ie501sp2
The flags to ls
are:
- force single-column output (
-1
) -- simply for ease of viewing
- do not descend into directories (
-d
)
- do not sort the incoming list (
-f
or -U
)
The zsh glob qualifiers say:
*(n/)
- expand to the list of directories /
, ordered numerically
*(n^/)
- expand to the list of items that are not ^
directories, ordered numerically
I mention a zsh solution just because you can then manipulate the results more easily, without having to worry about quoting filenames or delimiting them with nulls. For example:
$ mine=( *(/n) *(n^/) )
$ for file in "${mine[@]}"; do print -l "$file"; done
Foo
Ie7bar
Quux
Ie4 01
Ie4_01
Ie4!01
Ie4_128
Ie5
Ie6
Ie401sp2
Ie501sp2
$ print -l "${mine[-1]}"
Ie501sp2
ls
? A GUI file browser? – Jeff Schaller Sep 26 '18 at 15:58