1

In Ubuntu I can do a recursive search with a natural sort quite easily. A simple ls -1Rv will list file names only in a natural sort with all sub directories. An example output would be:

.:
test4
tmp2
tmp3

./tmp2:
test1
test2

./tmp3:
test3

It lists the current contents and then it traverses each directory. Everything is separated nicely.

With FreeBSD the -v option doesn't exist. When I didn't have sub directories I could do a ls -1 | sort -n for a natural sort. However, now that I have sub directories the pipe into sort -n doesn't work nicely. The ls -1R | sort -n predictably sorts into one giant list. An example output would be:

./tmp2:
./tmp3:
test1
test2
test3
test4
tmp2
tmp3

Instead of each sub directory separated in its own list, we have one giant list. Is there anyway to duplicate the ls functionality from Ubuntu in FreeBSD where I can get FreeBSD to list out and sort each list separately?

My searching has found topics like this, but they all use the pipe method and don't seem to talk on what happens with sub directories. I've also read the FreeBSD ls manual, but it does not mention having a natural sort. I didn't see anything helpful in the FreeBSD sort manual either.

1
  • Do you mean sort -n or sort -V ?
    – ilkkachu
    May 4, 2021 at 19:51

1 Answer 1

1

You might consider it cheating but you could install either:

Install:

pkg install lsd
pkg install coreutils

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .