I mean dear god look at these examples: https://stackoverflow.com/questions/9393607/find-and-replace....
Now somebody tell me I'm an idiot and recommend a commonly used program for the aforementioned problem please.
I mean dear god look at these examples: https://stackoverflow.com/questions/9393607/find-and-replace....
Now somebody tell me I'm an idiot and recommend a commonly used program for the aforementioned problem please.
rename 's/foo/bar/g' *
seems pretty unbeatable. If you need to choose the files more elaborately, combine it with find (I prefer xargs to -exec): find . -name '*.txt' -print0 | xargs -0 rename 's/foo/bar/g'
-print0 and -0 use null separators so can handle filenames with spaces etc.First: I'm looking for something like this: "rename -r . s/foo/bar/g" to recurse into subdirs. It might seem trivial, but things like find's -exec (a find idiosyncrasy) and xargs (I don't always remember how xargs -I works with extra arguments etc..) can add enough friction to the process where I just end up doing it manually with mv and it's not a fun time. I usually end up having to rename a few files (less than 20) across multiple directories (like changing a naming convention).
Second: The rename command your suggesting is actually a perl script that is indirectly symlinked with /usr/bin/rename on debian-derived distributions . And there can be at least 3 versions of this perl script by different authors under different aliases. See https://unix.stackexchange.com/questions/229230/whats-with-a...
On other distros -- well at least mine -- rename is a much dumber command with a different invocation (rename [options] expression replacement file) that is restricted to glob-style patterns (which incidentally is all I usually need anyways). Oh an you can also get this version on debian & co with the util-linux package. But why do I need that when I already have mv?
Anyways, the UNIX tools have terrible UI and terrible package management and everybody knows but I felt like saying it anyways...