Hacker News new | ask | show | jobs
by WizardClickBoy 651 days ago
100% agree. I'm currently preparing several 10s of GBs of HTML in nested directories for static hosting via S3 and was floundering until Gippity recommended find + exec sed to me. I'm now batch fixing issues (think 'not enough "../" in 60000 relative hrefs in nested directories') with a single command rather than writing scripts and feel like a wizard.

These tools are things I've used before but always found painful and confusing. Being able to ask Gippity for detailed explanations of what is happening, in particular being able to paste a failing command and have it explain what the problem is, has been a game changer.

In general, for those of us who never had a command line wizard colleague or mentor to show what is possible, LLMs are an absolute game changer both in terms of recommending tools and showing how to use them.

2 comments

If you have a lot of files, consider find piped to xargs with -P for parallelism and -n to limit the number of files per parallel invocation.

Only a tiny bit more complex but often an order of magnitude faster with today's CPUs.

Use -print0 on find with -0 on xargs to handle spaces in filenames correctly.

GNU parallel is another step up, but xargs is generally always to hand.

Thanks! Gippity did suggest the xargs approach as an alternative, but I found that

find [...] - exec [...] {} +

as opposed to

find [...] - exec [...] {} \;

worked fine and was performant enough for my use-case. An example command was

find . -type f -name "*.html" -exec sed -i '' -e 's/\.\.\/\.\.\/\.\.\//\.\.\/\.\.\/\.\.\/source\//g' {} +

which took about 20s to run

One can express your sed in less Leaning Toothpick Syndrome[1] via:

  find . -type f -name "*.html" -exec sed -i '' -e 's|\.\./\.\./\.\./|../../../source/|g' {} +
Using "/" as the delineation character for "s" patterns that include "/" drives me batshit - almost as much as scripts that use the doublequote for strings that contain no variables but also contain doublequotes (looking at you, json literals in awscli examples)

If your sed is GNU, or otherwise sane, one can also `sed -Ee` and then use `s|\Q../../../|` getting rid of almost every escape character. I got you half way there because one need not escape the "." in the replacement pattern because "." isn't a meta character in the replacement space - what would that even mean?

1: https://en.wikipedia.org/wiki/Leaning_toothpick_syndrome

Parallel is nice when doing music conversion with ffmpeg.
Primeagen detected

I find him hard to listen to when he does things like this

Primeagen is some kind of Youtuber? I am not familiar and don't understand what you are trying to convey here.
Guessing 'gippity' has been used by primeagen recently, so now you're gonna be tarred with the 18-23 React bootcamp graduate brush (at least that's who I imagine find him watchable).
It's a case of convergent evolution - I don't know where I heard it first, but I asked GPT if it minded and it said "Of course, you can call me Gippity!", so I do, because it's more fun.
yes, and a cringy one