This is just me celebrating a small win. I’ve been slowly learning bash scripting, and just now I was able to quickly write a simple bash script to automate a file moving task without referring to my notes or the web!

It’s not a super complicated script, I’m just happy I’m starting to internalize the knowledge I’ve been building.

I’ve been organizing my media files after ripping our DVD collection. I had all the files for The Smurfs cartoon (love the Smurfs) in the main Smurfs show folder. I wanted to put them all into their respective season folders (Season.XX). Here’s the script:

#! /bin/bash

for number in {01..09}; do
	find . -type f -name "The.Smurfs.S$number*" -exec mv {} Season.$number/ \;
done

I could have done it as a one liner, but I like to keep things like this for future reference.

  • LupusBlackfur@lemmy.world
    link
    fedilink
    arrow-up
    28
    arrow-down
    2
    ·
    4 days ago

    Pfft…

    Good job.

    The “one liner” thing is entirely overrated.

    Honestly, who the fuck cares…?? 🤷🤷

    • harsh3466@lemmy.mlOP
      link
      fedilink
      arrow-up
      6
      ·
      4 days ago

      Thank you! I always worry with a one liner that I’ll fuck something up in a bad way. In a script it helps me think about the process since it’s more visually structured, and for me it’s easier to test.

      • curbstickle@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        6
        arrow-down
        3
        ·
        edit-2
        3 days ago

        I’m with them, one line is for showing off, not utility.

        Utility has comments!

        Edit: BTW, throw a variable in there and you can set up your own handy rename/renumber script for anything!