This article is the first in a series of posts about automating everyday actions. We’ll start with Bash shell scripting, which allows you to write ...
For further actions, you may consider blocking this person and/or reporting abuse
Nice post.
My pedantry begins:
files = $(ls)
isn't going to work because you can't have spaces around the assignment operator.The script as you have it will do unexpected things if there are spaces in any of the path or filenames. I'd suggest using a
find
command and splitting the result by/
instead, then using the resulting variables inside double-quotes.It will also have issues if the filename starts with
-
becauseconvert
will interpret it as a flag.I tested the script and had two versions of it at some point (one in the body of the text and one I was executing), I must have left snippets of the wrong one in, you're correct, I'll fix it right now, thank you very much for noticing that.
P.S.: The issue with spaces around the assignment is in the first part of the post, I didn't pay as much attention to that as I should have and I usually leave spaces intentionally around operators when programming, I fixed that already. It wasn't there in the final script because I paid more attention with that one because I was in my usual
vim
Bash-scripting environment and not in a GUI text editor writing Markdown like I was for the earlier section.P.S. II: Regarding the potential issue with spaces in the path, I didn't think that was likely in the specific example, but I'll address that ASAP. I'll also credit you for your spot-on observations.
P.S. III: Regarding the issue with filenames starting with
-
, it actually would only be an issue if the first directory's name (thearea
) starts with-
, and that is easily fixed by changing the command fromconvert ${picture} (...)
toconvert ./${picture} (...)
Excellent post! Since I got my hands in Linux, I automate every repetitive task. The time you can save compared to the time that it takes to implement the automation is incredible.
For more complex automations I tend to use python but just because of PyPI
Thank you! Python is much more powerful, but a bit less intuitive for some tasks. I'll be posting about automating tasks with it in the near future too.
In the old days when using SVN, i created a file called
.
(dot)So i wanted to remove it, so i removed it...
rm -rf .
and commited.Since SVN is not distributed, you can guess what happened :D
I bet it wasn't great fun when it happened! These kind of mistakes are fun to talk about sometimes (long after the fact) as much as they are annoying to deal with when they happen. Making mistakes is a great way to learn, no amount of warnings and cautionary tales will stop you from making mistakes at some point, while repeating such a mistake more than once is much more rare, in Italian we would say "Non tutti i mali vengono per nuocere", which means something along the lines of "Not all that's bad ends up hurting you in the long term".
Yeah, first couple seconds were not fun... :D
But it quickly turned out, we had a guru sysop that literally brought back backup within 10 minutes after calling him, so i could laugh pretty soon :D
Bash scripting can be incredibly useful for automating everyday actions and tasks on your computer. Here are some common examples of tasks that you can automate using Bash scripting:
File Management:
Renaming multiple files at once based on a specific pattern.
Moving, copying, or deleting files and directories based on certain conditions.
Sorting files dddcodigo.com.br/ddd-34/ into different directories based on their file type or metadata.
Text Processing:
Searching for specific text patterns or keywords within files.
Extracting information from text files or structured data formats (e.g., CSV, JSON).
Formatting or modifying text data to meet specific requirements.
Linux automation tasks are a fundamental part of managing and maintaining Linux systems, offering numerous benefits for efficiency, reliability, and consistency. Here are some comments and insights on Linux automation tasks:
Linux automation tasks are a cornerstone of modern system administration, offering a wide range of benefits. However, it's important to approach automation thoughtfully, considering the specific needs of your environment and maintaining a balance between automation and human oversight. When done right, Linux automation can lead to more efficient, secure, and reliable systems.
Great article! 🙌
You should check out this Open-Source Introduction to Bash Scripting Ebook on GitHub as well!