3 ms·
When you need to rename 5000 files from abcd_small.jpg to abcd.jpg, how do you do that? rename s/_small// *_small.jpg When you have the string ABCD_XYZ in 5
by Symbiote 3y ago
When you need to rename 5000 files from abcd_small.jpg to abcd.jpg, how do you do that?
rename s/_small// *_small.jpg
When you have the string ABCD_XYZ in 50 files but you need to change it to DEFG_UVW, how do you do that?
perl -pi -e 's{ABCD_XYZ}{DEFG_UVW}' **/*(.)
When you need to move all the files ending '.png' into the directory 'PNG', and all the ones ending '.jpg' into 'JPG', how do you do that?
mkdir JPG PNG;
for i in *.png *.jpg; mv $i $i:e:u
- pjmlp 3y agoThere are GUI tools that do that, and thankfully most scripting languages have a REPL.
- Symbiote 3y agoI'll bet it takes longer to find and use a GUI tool for these. And a shell is a REPL.
- pjmlp 3y agoYou bet wrong, because naturally approaching 50y, I have my tools for quite some time, for the stuff I care about, not random examples on the Internet. A UNIX shell is a very bad approximation of a real programming language REPL. It is no accident that sh scripts turn into Perl, Python, Tcl, Lisp,... when one wants to keep sanity.
- JNRowe 3y agoAs we're in a zsh story, I'll point out it comes with a clever file renaming interface out of the box¹. It allows full access to all the advanced glob operators zsh provides too². ¹ https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#index-zmv https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht... ² https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filename-Generation https://zsh.sourceforge.io/Doc/Release/Expansion.html#Filena...
- eggdaft 3y agoOn the second one - if that’s in code than a good IDE will not only do it with a single keypress, but will also (optionally) do it intelligently eg change only in the code, not the comments, show you a browseable preview, and offer undo should you get it wrong. I like the shell but I also think IDEs are underrated.