Skip to main content
Topic: How to sort folders, different files using LS or TREE programs?  (Read 2362 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to sort folders, different files using LS or TREE programs?

 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


Re: How to sort folders, different files using LS or TREE programs?

Reply #1
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!


Re: How to sort folders, different files using LS or TREE programs?

Reply #3
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?

Re: How to sort folders, different files using LS or TREE programs?

Reply #4
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.

Re: How to sort folders, different files using LS or TREE programs?

Reply #5
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"

 

Re: How to sort folders, different files using LS or TREE programs?

Reply #6
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