Artix Linux Forum

Artix Linux => Installation / Migration / Configuration => Topic started by: tom-a on 11 July 2025, 18:13:46

Title: How to sort folders, different files using LS or TREE programs?
Post by: tom-a on 11 July 2025, 18:13:46
 Hello everyone.

The system loves order))

For example, I have a Sort folder for example.

Please tell me which team will sort over the alphabet at the top of the alphabet, then, for example, MP4, then MP3, ISO, TXT and they will be located in alphabet or the second option in size.

Code: [Select]
sort $  ls -l 
total 12
drwxr-xr-x 2 tom tom 4096 Jul 11 16:03 a-test1
-rw-r--r-- 1 tom tom    0 Jul 11 16:04 a-test1.txt
drwxr-xr-x 2 tom tom 4096 Jul 11 16:03 b-test2
-rw-r--r-- 1 tom tom    0 Jul 11 16:04 b-test.txt
drwxr-xr-x 2 tom tom 4096 Jul 11 16:03 c-test3
-rw-r--r-- 1 tom tom    0 Jul 11 16:04 c-test.txt



Code: [Select]
sort  $ tree -l
.
├── a-test1
├── a-test1.txt
├── b-test2
├── b-test.txt
├── c-test3
└── c-test.txt

4 directories, 3 files

Title: Re: How to sort folders, different files using LS or TREE programs?
Post by: ####### on 12 July 2025, 00:02:23
Using the Mate desktop and Caja, if you click on Edit - Preferences - Views you get a number of settings to configure regarding file arrangement. Some, but not all, of those settings can be made under View - Arrange Items instead.
Other desktop file browsers usually include similar options. Occasionally you might encounter other apps which include their own dialogue to locate files, and these might need setting individually if they provide this function.
If this is not what you are enquiring about then please elaborate further!
Title: Re: How to sort folders, different files using LS or TREE programs?
Post by: mrbrklyn on 12 July 2025, 00:07:53
see gawk

Also see Unix Powertools

https://www.oreilly.com/library/view/unix-power-tools/0596003307/

NYLXS has 2 copies in the library and a digital edition.
Title: Re: How to sort folders, different files using LS or TREE programs?
Post by: tom-a on 14 July 2025, 18:58:44
Guys, thank you for your answers.
Unfortunately, your advice did not work) In fact, if any Artix build had this function (alias), it would solve many problems, since by default all files (folders, text files, etc.) are scattered.

Now, for example, I have found a small solution:

Code: [Select]
#alias
alias ls='ls   --group-directories-first   --color=auto'

All my folders are alphabetically arranged on the left, now I want the other file types (txt,png,jpeg,iso etc) to be in the same alphabetical order, what other part of the command will do it?
Title: Re: How to sort folders, different files using LS or TREE programs?
Post by: Ambie on 15 July 2025, 07:44:35
I didn't fully understand what you want to achieve but ls has --sort parameter.

Code: [Select]
ls --group-directories-first --sort=extension

Read ls man.
Title: Re: How to sort folders, different files using LS or TREE programs?
Post by: Caramon2 on 19 July 2025, 10:46:21
Now, for example, I have found a small solution:
Code: [Select]
#alias
alias ls='ls   --group-directories-first   --color=auto'
Thanks for the inspiration. :)

I looked at the ls-manpage and found this for you: "-X     sort alphabetically by entry extension" and that for me (~/.bashrc):
Code: [Select]
alias ls='ls --color --group-directories-first -ANvx'
alias ll='ls --time-style=+"%F %T" -Fin'
Perfect! :D

Edit:

Added "-v     natural sort of (version) numbers within text"
Title: Re: How to sort folders, different files using LS or TREE programs?
Post by: tom-a on 22 July 2025, 21:33:21
I didn't fully understand what you want to achieve but ls has --sort parameter.

Code: [Select]
ls --group-directories-first --sort=extension

Read ls man.


Thank you very much  your command worked, the rest of the commands that users wrote and even chatgpt are not))
Now I see first all the folders alphabetically, then pdf  files, then txt, then mpeg4, etc