Sometimes the Linux command line feels like black magic. I just wrote this for a real, non-work-related task:

rename -v 's/^([0-9]{4}) - (.*)\.(.{3})$/$2 ($1).$3/' *

…and it worked!

Bonus nerd points to whoever figures out what I was doing. ;)

@cassidyjames you added a space to a filename... :( :( :(

I don't even want to guess what media rip you just ruined. ;)

Follow

@funnylookinhat it’s 2021, we can have human-readable filenames, damn it!

@cassidyjames @funnylookinhat i regret to inform, it just ain’t true. especially if you plan to do anything with those filenames in unix shell later. sure you can backslash escape the spaces, or quote the variables. iyou can also skip the broken step every time you walk down those stairs to avoid breaking your leg. it doesn’t mean any of this is good or safe design.

personally, i prefer to use something like
ls | perl -pe [regex noise] | sh
to generate something like
mv [oldname] [newname]

@cassidyjames @funnylookinhat this gives the opportunity to examine what the script is going to actually do *before* i irreversably rename all my files to the same file named %2.png

@zens @cassidyjames @funnylookinhat About the only MSDOS feature I'm happy to miss is the ability of rename to take a wildcard for source and destination, and get it right ...

@yojimbo @cassidyjames @funnylookinhat it’s good that regex back references use $n \\n \n or %n depending on context. it’s not an annoying hazard at all, and never leads to any data destroying mistakes

@zens @funnylookinhat first, naw. I spend way more time looking at files in a file browser, if I even look at them. I value human readability far, far above command-line friendliness.

Second, `rename -n` gives you a verbose previous of what it's going to do. So I use that first to make sure I got it right.

@cassidyjames @funnylookinhat I agree that human friendliness in filenames is important. i am just aggrieved of the way they have been implemented in unix-ish operating systems- by conflating the “human friendly” name with the programmatic reference name in unix shell, leading to a situation where the meaning of the space character is overloaded

@cassidyjames @funnylookinhat that is to say “human friendly” names are extra human unfriendly from the shell script view of the world

@cassidyjames @funnylookinhat it’s less a problem in languages where there is no way to reference a filename without it being quoted, and variables don’t work by substitution into program text, so don’t lull you into the false sense that leaving variables containing filenames unquoted is safe.

still, pain in the ass to have to replace spaces with %20 in urls to get that 100% xhtml compliance score.

@cassidyjames @funnylookinhat thus begins my argument for why we should abandon unix shells altogether and replace it with something fundamentally similar but without all the obvious painful and dangerous design flaws

@cassidyjames @funnylookinhat also… looks like "rename" is not a standard unix util. easily installable, but couldn't be relied upon in scripts that have to run on on a diversity of bare bones systems which-- I somehow manage to always encounter.

@zens @cassidyjames @funnylookinhat Like switch to fish shell, which is a shell where you don't have to worry about spaces in filenames by default?

(Most other shells, notably Bash, you have to dance around, set IFS, and such.)

And/or use GUI tools.

(I do both: I try to use graphical tools mainly and also use fish at the command line. And I also have lots of spaces in file names too.

If I write a script for others, I use sh/bash and shellcheck.)

@garrett @cassidyjames @funnylookinhat
I pine for a tool that doesn't exist, where I can type in my shell script and the script actualises into a blocks based visual programming language program. A a bit of templating and hypercard inspired gui design later and you have a nicely packaged up gui tool for entering parameters into the script and rerunning it at will.

@garrett @cassidyjames @funnylookinhat

Silly and impractical ? probably. But it would be good for, /yknow, not needing to look up the command for converting png to jpg in bulk using image magick the umpteenth time.

@garrett @cassidyjames @funnylookinhat plus, it would be good to have systems that acknowledge that building a new application from scratch, and slightly modifying a thing that already exists, are fundamentally different activities.

@garrett @cassidyjames @funnylookinhat

That's the sorta thing, except there's plenty of legit criticisms of visual programmingn in general, and scratch-style thingies in particular, which is why I have in my head some magical system where the blocks are somehow also a kind of rich text. Like halfway between intellisense and blockly.

@zens @cassidyjames @funnylookinhat the whole "no spaces in filenames" is dorky FUD. I've had my music library organized with proper filenames for more than a decade. Same with video games. Software that can't deal with spaces in filenames is buggy and broken software (like some old MojoSetup installers). Only reason not to have spaces in filenames is because they look like crap when served over HTTP, but otherwise it's perfectly fine.

@strider @cassidyjames @funnylookinhat right, well, then i reserve the right to glue saran wrap over your toilet bowl next time someone sends me assets with spaces in the filename for a website they expect me to build.

@strider @cassidyjames @funnylookinhat don’t worry, it’s fine. the idea clear wrap over the toilet bowl being a nasty prank is just nerdy FUD

@zens @cassidyjames @funnylookinhat part of building a website is serving assets with a decent URL, it's part of the job. I build websites, I understand that. I dont expect people to change their naming conventions because I want my job to be easier.

@strider @cassidyjames @funnylookinhat well, that’s the difference between you and me then, i guess. i expect other people to care about their own shit at least as much as I do, which admittedly isn’t that much, but come on, “Final Final Copy 2.docx” ?

@zens @cassidyjames @funnylookinhat eh, I've been guilty of naming atrocities like "06-system_of_a_down-chop_suey-stc.mp3". I'm just grateful that software like Musicbrainz Picard can easily fix those past mistakes.

@cassidyjames @funnylookinhat underscore and capital letter can live side by side. But I hate CL!

Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!