3 ms·
The best part of all that is that I would LOVE a UNIX command to quickly bulk replace filenames against a pattern instead of some multi-pipe bash loop incantati
by helaoban 4y ago
The best part of all that is that I would LOVE a UNIX command to quickly bulk replace filenames against a pattern instead of some multi-pipe bash loop incantation that I usually resort to (when banging out mv x y on 30+ files is really too dumb to stomach). Simple binary sans node please, but the idea is great.
I mean dear god look at these examples: https://stackoverflow.com/questions/9393607/find-and-replace-filename-recursively-in-a-directory 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.
- nixpulvis 4y agoI've been happy with `rename` when I need it.
- mkl 4y agoYes, rename sounds like exactly the tool for the job, very simple and quick. But several answers in that "dear god look at these examples" StackOverflow thread do use rename (sometimes embedded in find commands or other), so I'm not sure what OP is looking for. 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.
- helaoban 4y agoWell, 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-all-the-renames-prename-rename-file-rename 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...