I have some files with their names starting with 00, 01, ..., but there can be multiple filename with the same number i.e. 00_filename1, 00_filename2. I want to list them sorted by their names, but if there are more files with the same starting number, I want them to be sorted by the date of modification (in descending order) too.
So instead of this:
Oct 31 19:05 00_trash
Oct 31 19:14 00_trash_00
Oct 31 18:57 01_creating_dirs.py
Oct 31 19:05 01_trash
Oct 31 16:20 02_creating_csv.py
Oct 31 19:22 02_renaming_files.sh
Oct 31 16:20 03_creating_db.py
Oct 31 19:06 03_trash
Oct 31 16:21 04_importing_csv_to_db.py
Oct 31 16:20 05_some_xl.py
Oct 31 16:22 06_regex.py
I want then to be sorted like this:
Oct 31 19:14 00_trash_00
Oct 31 19:05 00_trash
Oct 31 19:05 01_trash
Oct 31 18:57 01_creating_dirs.py
Oct 31 19:22 02_renaming_files.sh
Oct 31 16:20 02_creating_csv.py
Oct 31 19:06 03_trash
Oct 31 16:20 03_creating_db.py
Oct 31 16:21 04_importing_csv_to_db.py
Oct 31 16:20 05_some_xl.py
Oct 31 16:22 06_regex.py
I have tried combining ls
(using arguments -t
and -r
) with sort
(using arguments -kn,m
- where n,m
specify the range of columns - and -r
), but after hours of searching and trying I did not success.
zsh
I think - using glob qualifiers likeprint -RC1 *(oe:'REPLY=${REPLY%%_*}':om)