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

print only filename #1037

Open
apprehensions opened this issue Jun 9, 2022 · 9 comments
Open

print only filename #1037

apprehensions opened this issue Jun 9, 2022 · 9 comments

Comments

@apprehensions
Copy link

What version of fd are you using?
fd 8.4.0

to put it simply, i just want the filename .
eg. instead of /home/user/file i would like file.

i know this is possible via --exec (personally i think it would be slower because it is executing a seperate binary of some sort.), but seeing how find has it using printf or using basename but isn't there a cleaner way? or rather a solution?

@tavianator
Copy link
Collaborator

Like you said, it's possible with --exec, or better, --exec-multi:

$ fd -X printf '%s\n' {/}

But you're right, it is slower than find -printf:

Command Mean [ms] Min [ms] Max [ms] Relative
fd -uu -X printf '%s\n' {/} 223.5 ± 4.3 214.5 227.4 3.40 ± 0.08
find -printf '%f\n' >/dev/null 87.7 ± 1.0 86.0 90.1 1.33 ± 0.02
bfs -printf '%f\n' >/dev/null 65.7 ± 0.9 64.2 68.4 1.00

However, I'm not sure what level of customizability is worth adding to fd. I could imagine reusing the placeholders from --exec:

$ fd --format {/}

@tmccombs
Copy link
Collaborator

I like the idea of a format option that uses the same template syntax as exec

@apprehensions

This comment was marked as outdated.

@tavianator

This comment was marked as outdated.

@sharkdp
Copy link
Owner

sharkdp commented Jun 12, 2022

I like the idea of a format option that uses the same template syntax as exec

Would the syntax be --format <placeholder>, or could users supply arbitrary strings that would include a placeholder pattern. As in --format 'found file {/} in directory {//}'?

@tmccombs
Copy link
Collaborator

The latter, i think.

@balta2ar
Copy link

balta2ar commented Jul 2, 2022

My use-case for customizable output format is to find & print N last created/modified files:

$ find -type f -type f -printf '%TY-%Tm-%Td %Tr %p\n' | sort -r | head -3
2022-06-25 03:28:06 PM ./gn-m85/style_guide.md
2022-06-25 03:28:06 PM ./gn-m85/standalone.md
2022-06-25 03:28:06 PM ./gn-m85/reference.md

@Robert-Ernst
Copy link

Why such an obvious request is still not implemented?
I will never remember to type fd -X printf '%s\n' {/} just to get only the filename.
If fd want to be better than find, then maybe implement features which are convenient.

@tmccombs
Copy link
Collaborator

It's mostly implemented in #1043 (comment).

The next step is benchmarking it, which I haven't gotten around to. Partly because I'm not confident in my benchmarking skills.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants