ShellCheck

Today I learned about ShellCheck, a static analysis tool that “finds bugs in your scripts”. It can and should be run on the command line, but an online version is also available. It catches most style and syntax errors and has plenty of options, like ignoring specific errors and warnings, which is helpful in CI scenarios.

July 24, 2024

Bash-Oneliner: a collection of terminal tricks for Linux

Bash-Oneliner is an excellent resource for Bash/Linux users. Most of the “tricks” are well-known, but there is always something to learn. More importantly, finding them all well organized in one file is rare. I use the reverse lookup of bash-history (Ctrl+R) daily. Still, only today (thanks to an HN comment on Bash-Onliner) did I learn that it also preserves one’s comments, which can be exploited to invoke complex commands quickly:...

July 22, 2024

How to fix the crontab error `rename: Operation not permitted`

Today, something unexpected happened while I was working on one of our Linux machines. I issued the crontab -e command to add a cron job to my user’s crontab file, modified and saved it, only to the following error: crontab: installing new crontab crontab: crontabs/<user>: rename: Operation not permitted crontab: edits left in /tmp/crontab.hgmsOH/crontab Puzzled, I checked whether my user permissions were all right, if the disk was full, and several other things....

January 25, 2024

How to use bash to recursively search and replace a string in all directory files

Another achievement I unlocked with the recent website update is the newsletter switch from Substack to a fantastic and independent provider, Buttondown. That required updating all the “subscribe to my newsletter” links. We’re talking 5K posts, all saved as individual files in the same directory. The bash command that did that for me is: find content/post/*.md -type f -exec \ sed -i .bak 's|https://nicolaiarocci.substack.com|https://buttondown.email/nicolaiarocci|g' {} + It is pretty straightforward. find looks for all markdown files in the content/post/ directory....

January 6, 2024

rsync with a different user

Today I learned how to rsync with a user different than the one connected to the remote. Why would one want to do such a thing? The data I need to download from that server is owned by ‘backup,’ a different, service-only user. I wanted to avoid going the change-permissions slippery route and allow my user direct access to the data. Looking at the rsync documentation, I learned about the nifty --rsync-path=PROGRAM option:...

August 23, 2023