this post was submitted on 16 Feb 2025
5 points (100.0% liked)

Linux

51580 readers
1241 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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.

top 5 comments
sorted by: hot top controversial new old
[–] ookiiBoy@lemmy.blahaj.zone 1 points 3 weeks ago (1 children)

Look up "shellcheck", find a plugin for your editor. It should help a lot.

[–] atzanteol@sh.itjust.works 1 points 3 weeks ago

This is excellent advice. Bash is fantastic but it has a lot of "foot guns" that can cause problems. Especially where spaces are concerned...

Op: good job with the script

[–] lupusblackfur@lemmy.world 1 points 3 weeks ago

Pfft...

Good job.

The "one liner" thing is entirely overrated.

Honestly, who the fuck cares...?? 🤷🤷

[–] electric_nan@lemmy.ml 0 points 3 weeks ago (1 children)

I have studiously avoided learning any bash scripting for the 17 years I've used Linux, so all I can say is good job! Actually just today I found a command that I needed to get a certain appimage to run without crashing, and I remembered enough that I was able to make it into a script (I struggle with whether it's !# or #!). Having just done it today, I can confirm you don't need to include '/bin/bash', just FYI. I believe that is assumed.

[–] LeninOnAPrayer@lemm.ee 1 points 3 weeks ago* (last edited 3 weeks ago)

~~It makes it usable without typing bash~~. Same would apply for a python script. For example you can make a python script named with no extension and add #!/usr/bin/python to the top of the file. Bash shell sees this and knows to execute the script using that python path.

Then you just include the directory in your $PATH and chmod +x the script. Then you can type $python_script instead of $python python_script.py