Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommended way to sort results #196

Closed
flip111 opened this issue Dec 10, 2017 · 17 comments · Fixed by #556
Closed

Recommended way to sort results #196

flip111 opened this issue Dec 10, 2017 · 17 comments · Fixed by #556
Labels

Comments

@flip111
Copy link

flip111 commented Dec 10, 2017

Before with find i could use the printf option https://unix.stackexchange.com/a/29901/196971

what the best way to solve this with fd ?

@sharkdp
Copy link
Owner

sharkdp commented Dec 14, 2017

What about using xargs?

> fd -0 foo | xargs -0 ls -ltr
@flip111
Copy link
Author

flip111 commented Dec 15, 2017

It works .. so i will close this issue. It would be nice to have a sorting flag that keeps coloring in the output. Or alternatively a flag to execute a command for all the results (fd -X "ls -ltr" foo path).

@rien333
Copy link

rien333 commented Jan 4, 2020

@sharkdp Is that still the recommended way? Something like fd -e pdf -X ls -t seems to work just as fine as the xargs equivalent.

@sharkdp
Copy link
Owner

sharkdp commented Jan 4, 2020

@rien333 You are right. I would now recommend to use the -X option, simply because it is easier to type 👍

sharkdp added a commit that referenced this issue Apr 2, 2020
Add a new `-l`/`--list` option to show more details about the search results. This is basically
an alias for `--exec-batch ls -l` with some additional `ls` options.
This can be used in order to:
    * see metadata like permissions, owner, file size, modification times (#491)
    * see symlink targets (#482)
    * achieve a determinstic output order (#324, #196, #159)
    * avoid duplicate search results when multiple search paths are given (#405)
sharkdp added a commit that referenced this issue Apr 2, 2020
Add a new `-l`/`--list` option to show more details about the search results. This is basically
an alias for `--exec-batch ls -l` with some additional `ls` options.
This can be used in order to:
    * see metadata like permissions, owner, file size, modification times (#491)
    * see symlink targets (#482)
    * achieve a deterministic output order (#324, #196, #159)
    * avoid duplicate search results when multiple search paths are given (#405)
sharkdp added a commit that referenced this issue Apr 3, 2020
Add a new `-l`/`--list` option to show more details about the search results. This is basically
an alias for `--exec-batch ls -l` with some additional `ls` options.
This can be used in order to:
    * see metadata like permissions, owner, file size, modification times (#491)
    * see symlink targets (#482)
    * achieve a deterministic output order (#324, #196, #159)
    * avoid duplicate search results when multiple search paths are given (#405)
@sharkdp
Copy link
Owner

sharkdp commented Apr 3, 2020

There is a new way to do this now: With #556 implemented, you can simply use fd -l to run ls -l in the background:

This is now supported (in a particular way) by the new -l/--list-details option, see #556.
image

@sharkdp
Copy link
Owner

sharkdp commented Apr 16, 2020

This has now been released in fd v8.0.

@sergeevabc
Copy link

sergeevabc commented Jan 7, 2024

This is now supported (in a particular way) by the new -l/--list-details option, see #556.

$ fd -l
[fd error]: 'fd --list-details' is not supported on Windows unless GNU 'ls' is installed.

Fail.

Still looking for a native way to sort the output in alphabetical order SINCE 2018.
Damn, folks, what's wrong with implementing much requested --sort flag?

@rien333
Copy link

rien333 commented Jan 7, 2024

What's wrong with installing GNU's ls? If a system can acquire and install fd, wouldn't it be fairly easy to also install some GNU (compatible) tools?

@sergeevabc
Copy link

sergeevabc commented Jan 7, 2024

@rien333, yeah, then let's refuse to build the app for other platforms at all, saying that once user is able to download this app, then why not install the whole Unix zoo as well. After all, it's free, it's easy peasy lemon squeezy, it means less troubleshooting and more time for developing new features. Hooray, my eye.

Do you know what portability means? I mentioned -l flag as a poorly done job: the flag is there, but it doesn't do any good out of the box. How about making a player and then require users to surf the Internet in search of desired format decoders? Let's have some more fun: --upload to save output remotely (if Curl is installed), --pdf to save it for print (if Ghostscript is installed), --morse to convert it to audio tones for people with poor vision (if FFMPEG or Sox is installed). Anything but a native sort in a standalone app that outputs paths, right.

And most importantly ls is not a solution to the sorting problem, it's an attention theft, whereas human attention is a scarce commodity. Just look at this mess:

$ fd -H -g "_startup" -l
-rwxrwxrwx 1 somebody somegroup 0 Jan  7 10:03 '.\Autohotkey\_startup'
-rwxrwxrwx 1 somebody somegroup 0 Jan  7 05:28 '.\DNSCrypt\_startup'
-rwxrwxrwx 1 somebody somegroup 0 Jan  7 05:28 '.\Keepass\_startup'

What are rwxrwxrwx somebody somegroup under Windows? What's wrong with time?

I need a list of paths in alphabetical order, nothing more.

$ fd -H -g "_startup" --sort
Autohotkey\_startup        ^ this flag is not implemented yet
DNSCrypt\_startup
Keepass\_startup

Since this app outputs paths, it's crucial to provide different popular ways to display these paths. Just like base64 allows you not only to encode and decode data, but to vary the column width, like du allows you to measure size using powers of 1000 besides 1024, like magick allows you to get color values as RGB, HEX, HSL… without extra code golf.

@rien333
Copy link

rien333 commented Jan 7, 2024

I mentioned -l flag as a poorly done job: ... I need a list of paths in alphabetical order, nothing more.

I do not think you have explained the connection between -l and sorting, actually?

then why not install the whole Unix zoo as well.

If your OS has no way to the sort/filter lines of output, then this is not even that bad of an idea, especially because that "zoo" of extremely portable utilities is just 16MB in size. My guess, however, is that windows does already have such text manipulation capabilities, making fd usable out of the box on common operating systems.

Also, and not sure what it got to do with anything, but I agree that the output of ls -l can be a bit much.

@tmccombs
Copy link
Collaborator

tmccombs commented Jan 8, 2024

I mentioned -l flag as a poorly done job: the flag is there, but it doesn't do any good out of the box

The -l option is basically an alias for -X ls -l -h -d

If you don't have ls installed, there isn't much it can do.

Maybe there is some roughly equivalent powershell command it could run instead? But then the output would be very different on windows than other platforms, and would either be different depending on whether you had GNU ls installed, or would never be consistent with other environments (if we always used a powershell command).

FWIW, AFAIK, none of the maintainers of fd use Windows, so support of Windows is mostly best-effort. If you think windows support could be improved in some way, PRs are welcome :).

And most importantly ls is not a solution to the sorting problem, it's an attention theft, whereas human attention is a scarce commodity. Just look at this mess:

I think the discussion of the -l option has confused you a little bit. The relevance of -l to sorting is not that it sorts the output, but that it will output additional fields which can be used by another command to sort by (for example the mtime).

I need a list of paths in alphabetical order, nothing more.

So in your case, assuming that since you are on windows, you are using powershell, you can just pipe the output to Sort-Object.

what's wrong with implementing #324 #789 --sort flag?

It doesn't really add much value over composing fd with existing tools (depending on your operating system) to sort the output.

@flip111
Copy link
Author

flip111 commented Jan 9, 2024

The relevance of -l to sorting is not that it sorts the output, but that it will output additional fields which can be used by another command to sort by (for example the mtime).

Are you suggesting that the output should be parsed again by another command? In that case it is probably better to use ls or powershell equivalent and make them sort directly.

It doesn't really add much value over composing fd with existing tools (depending on your operating system) to sort the output.

That's precisely the point why the -l flag is weird, it doesn't really add much value over composing fd with existing tools to list to output details. You get this single flag from ls ls -l from a single platform (linux). It's not composing programs, as is well known on linux. And it's not full featured enough to be a complete solution for use cases like sorting, because you still need to pipe.

Specifically for the -l flag no effort has been made to add windows support for it (no blame, just fact), so it's broken on windows. That's a choice to say fd will work well on linux and not on windows, but you can also choose not to have the -l flag and use platform specific tools with -X. I can imagine the frustration of windows users when windows binaries are released without settings expectations that features don't work as you would expect.

I do not think you have explained the connection between -l and sorting, actually?

IMO there is also no relation on the actual usage of the tool. It became connected because this topic is about sorting and sharkdp said:

There is a new way to do this now: With #556 implemented, you can simply use fd -l to run ls -l in the background

For me it's also not clear what this has to do with sorting ...


IMO this -l flag discussion is off-topic because it's not the recommended way to do sorting with fd #196 (comment)

@tmccombs
Copy link
Collaborator

tmccombs commented Jan 9, 2024

Have you read the unix stackexchange link from the OP? Despite the title, the original request for this issue was how to do the equivalent of

find . your-options -printf "%T+ %p\n" | sort

and note that that still uses sort.

The relevance of -l is that currently, one way to accomplish that with fd would be that the -l output includes the date, which could be used as a sorting field. Although, it isn't in a format that is very sortable, so I think -X ls -t would still be a better way to accomplish that.

And yes it does rely on a unix-specific tool. But there probably is a way to do tthe same on windows as well, but I'm not familiar enough with windows to know what that is.

@flip111
Copy link
Author

flip111 commented Jan 9, 2024

Have you read the unix stackexchange link from the OP?

I am the Original Poster. The stackexchange post was as an example of the kind of functionality i wanted (the outcome) not a specific request to do something with flags and/or pipes.

Although, it isn't in a format that is very sortable, so I think -X ls -t would still be a better way to accomplish that.

I agree with you.

@xxyxxyxyx1
Copy link

Does anyone have a recommendation for sorting and using an -X / -x argument together? Sometimes I would like the files to be sorted before they are sent to the other program.

@rien333
Copy link

rien333 commented Jun 6, 2024

If the final program in the chain accepts a list of files as input (which a lot of unix tools to do) you may be able to get away with something like this instead (at least in fish shell):

# find all mp3s, sort them, and then call another program (e.g. du) on this sorted list
du -h (fd -emp3 | ... # your sorting routine here)

Or a much more ugly approach:

du -h (ls -t (fd -emp3))

The above gives you a list of mp3s with their respective size, sorted by their modification date.

I think doing this within a single fd command would involve implementing some kind of pre-sorting mechanism/flag, which may well be out of scope.

@tmccombs
Copy link
Collaborator

tmccombs commented Jun 6, 2024

You can pipe to sort, then pipe that result to xargs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6 participants