7 ms·
I really like the approach of pipe-rename (https://github.com/marcusbuffett/pipe-rename https://github.com/marcusbuffett/pipe-rename) for renaming many files. I
by dystroy 4y ago
I really like the approach of pipe-rename (https://github.com/marcusbuffett/pipe-rename https://github.com/marcusbuffett/pipe-rename) for renaming many files. It's especially convenient for people who can efficiently edit many lines in their favorite text editor (so everybody here, I guess).
Main problem: you maybe don't do this kind of operation frequently enough to remember how it's called or how you aliased it.
- tomsmeding 4y agoGiven that I'm guaranteed to forget that I have this thing installed if I would install it, I'm just going to steal the idea and try to remember to use my editor instead of an ugly shell loop next time I want to rename many files. There's only a small difference, really, between transforming `1.txt 2.txt 3.txt` to `file1.md file2.md file3.md` and transforming to `mv 1.txt file1.md; mv 2.txt file2.md; mv 3.txt file3.md`.
- chrisshroba 4y agoYou likely already know this, but just a reminder/tip that bash and zsh will let you edit the current command you’re entering in your editor of choice if you press ctrl+x ctrl+e (without releasing ctrl between). (Note if you’re using zsh without ohmyzsh, you’ll have to enable this manually [1]) [1]: https://nuclearsquid.com/writings/edit-long-commands/ https://nuclearsquid.com/writings/edit-long-commands/
- remram 4y agoI don't see how the shell could know whether you released the Ctrl key?
- chrisshroba 4y agoWhoops, you're right, I assumed my muscle memory was the source of truth heh.
- jwilk 4y agoSounds a bit like vidir from moreutils.
- globular-toast 4y agoIt is a good approach. Emacs has dired and other modes for doing this.
- dan-robertson 4y agoTo expand on this: if you look at a dir in Emacs then change the buffer to be writable, you can change file names and saving the buffer renames files. You can also edit the permissions columns in a similar way. And there is vc integration so eg eMacs will hg mv files in a mercurial repo.
- globular-toast 4y agoI didn't know about the VC integration. After 15 years emacs can still surprise me!
- rich_sasha 4y agoMy approach is something like $ ls / find # tweak until I have a list of things to rename $ for file in $(ls / find...); do echo "mv $file $(echo $file | sed ... )"; done # this prints mv commands for renaming, I can inspect them as needed $ for file in $(); do...; done | sh # execute the renaming It is inspectable, easy to cancel (just don't pipe to shell), incremental... just needs wrangling with bash etc. which is a bit of a pain. It works for a bunch of other all-or-nothing commands, which are potentially quite destructive; use a for-loop to generate the commands, tweak until you're happy with it, then pipe to shell.
- da39a3ee 4y agoThanks! I do this but go in and remove the echo. For some reason I hadn’t thought to pipe to a shell interpreter.
- GoblinSlayer 4y agoThe demo requires a sufficiently smart editor. But with a sufficiently smart editor you can prepare a script and pipe it into an interpreter.
- gorgoiler 4y agoPipe rename automates the following common script in a much nicer way: !ls qaVypImv “escapeA” escapeJi”escapeA”escapejq99@a
- Erwin 4y agoI like that idea of converting metadata to text, so you can do text operations on it that you are already familiar with, and then apply the changes back. If your problem can be solved by just regexps, there's a "rename" tool installed by Perl I've used for decades. E.g. rename -n 's/JPEG$/jpg/' *JPEG Will apply the substitution for JPEG at end of the filename to just jpg. The -n will run without renaming so you can see what it intends to do.
- greazy 4y agoA newer tool 'brename' is similar but uses standard inputs and allows for full regex. Like rename it has dry mode for safe renaming.
- jwilk 4y agoBeware there are two incompatible rename programs in the wild. :( What you have installed, and what Debian and its derivates ship is this: https://metacpan.org/pod/distribution/File-Rename/rename.PL https://metacpan.org/pod/distribution/File-Rename/rename.PL Most(?) other distros ship the one from util-linux: http://man7.org/linux/man-pages/man1/rename.1.html http://man7.org/linux/man-pages/man1/rename.1.html
- ChrisGranger 4y agoWe had the same idea at the same time. For a command line newbie trying to follow a tutorial, it can certainly be confusing.
- ChrisGranger 4y agoNote that the rename tool bundled with some distributions is not the Perl version. If someone is looking to install it, it may also be called perl-rename.
- nxbp 4y agoLooks like a glorified version of qmv from renameutils? (https://www.nongnu.org/renameutils/ https://www.nongnu.org/renameutils/)
- justsomehnguy 4y agols | % {rename-item $_ -newname $('myfile_' + ($_.BaseName -replace '\D') + '.md' )} No need to remember anything.
- michaelmior 4y ago</sarcasm>? I would be much more likely to remeber ls | renamer than figure out how to write such a command.
- justsomehnguy 4y ago> </sarcasm>? Nope. > to remeber That's the point, you don't need to remember anything, it would come naturally after a day of tinkering with PS/pwsh. You just write it for your current needs. This example was just a quick one-liner, it's very simple: ls | % { # get the file list, cycle for each item rename-item # obvious usage: rename-item oldname newname $_ # pretty obvious, the source - place the loop variable here ie file name -newname # explicit calling for a parameter name, isn't really needed $( # subroutine start or eval if you prefer, to construct the new file name: # 'text' + (take property basename from the file and regex it) + 'text' 'myfile_' + ($_.BaseName -replace '\D') + '.md' ) # subroutine end } # cycle end. It could be simplified (in this example) to this: ls | % { $a = 'myfile_' + ($_ -replace '\D') + '.md' rename-item $_ $a } which could be even written as a one-liner if you prefer it right now, just add a semicolon after `$a = ...` ls | % {$a = 'myfile_' + ($_ -replace '\D') + '.md'; rename-item $_ $a }
- l2dy 4y agoThis is a lot to remember, and a typo could mess things up badly.
- nmaggioni 4y agoSome time ago I have in fact written a small utility based on fzf that solves this problem by letting you comment aliases in your shell config file and fuzzy-search through them: https://github.com/nmaggioni/wat https://github.com/nmaggioni/wat The tag system is especially useful to me when I know the general concept I'm after but don't remember the exact wording of the command.
- southerntofu 4y agoFrom a quick look I love it! I just wish something like that was part of my shell and it not only applied to aliases... :)
- anthk 4y agoJust use vidir from moreutils.
- yboris 4y agoOMG! I created a GUI tool for this: Simplest File Renamer (Win, Mac, Linux). In my app, you can rename using your favorite code editor, so you have access to all your keyboard shortcuts. https://github.com/whyboris/Simplest-File-Renamer https://github.com/whyboris/Simplest-File-Renamer - MIT open source
- encryptluks2 4y agoExcept the previous example relies on Rust and the shell, while yours relies on Angular/Electron.
- yboris 4y agoSorry, by "this" I meant "the same functionality - rename files via text file" :)
- rsync 4y ago" ... renaming many files ..." I think folks should be aware of 'vimv' which opens your pwd in an editor and you just edit your filenames in 'vi' ... and all of the renaming happens upon saving and quitting. Not sure if this is the official/canonical distribution, but for what it's worth: https://github.com/thameera/vimv https://github.com/thameera/vimv
- Existenceblinks 4y agoEverything that needs manual entry can utilize text editor features greatly! Search and replace, multiple cursors, duplication, formatting etc. However, there will require some fancy ways to put result back in input sources.
- lenkite 4y agoZSH has mmv for this.