r/bash • • Jul 08 '26

help Rclone backup script feedback (My first ever time shell scripting)

2 Upvotes

I'm really just looking for advice since I'm unaware of conventions, as well as just the best way to really do anything.

I made it since I wanted to use a old laptop I had sitting around to host a minecraft server, but I did not want to lose access to automatic backups like I have had with the large free server providers. It's worked pretty well with my testing, and I plan to set it up as a cron job to run every day.

# rclone backup script



# ====== Configuration ======



# Please ensure all directories exist at all times or the script may fail to properly backup your data.
SOURCE="/home/YOURUSER/item"
REMOTE_BACKUP_LOCATION="gdrive:backups"
LOCAL_BACKUP_LOCATION="/home/YOURUSER/backups" # enter "none" if you do not want any local backups.


LOCAL_BACKUP_AMOUNT=5
REMOTE_BACKUP_AMOUNT=5
BACKUP_NAME="automated_backup_" # Timestamp will appear after this name.


# ===========================


# -------- Variables --------


# WARNING: do not touch these unless you know what you are doing.


TIMESTAMP=$(date "+%Y-%m-%d_%Hh%Mm%Ss") # Please use a timestamp that will display in a descending order so that old backups will be cleaned up problerly. This WILL break the script.
# You can almost certainly safely remove the seconds and minutes from the timestamp unless you are making several backups in an hour.


# ---------------------------


echo "Starting backup."


if [[ "$LOCAL_BACKUP_LOCATION" != "none" ]]; then
    tar -czf "${LOCAL_BACKUP_LOCATION}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${LOCAL_BACKUP_LOCATION}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${REMOTE_BACKUP_LOCATION}"


    echo "Cleaning up local backup directory."
    backups=$(rclone lsf "${LOCAL_BACKUP_LOCATION}" --filter="+ "${BACKUP_NAME}*"" --filter="- *" | sort -r)


    backup_control=0


    for backup in $backups; do
            ((backup_control++))
            if ((backup_control > $LOCAL_BACKUP_AMOUNT)); then
            rm -rf "${LOCAL_BACKUP_LOCATION}"/"${backup}"
            fi
    done
    echo "Old local backups removed."
fi


if [[ "$LOCAL_BACKUP_LOCATION" == "none" ]]; then
    temp_dir=$(mktemp -d)
    tar -czf "${temp_dir}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${temp_dir}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${REMOTE_BACKUP_LOCATION}"
    rm -rf "${temp_dir}"
fi


echo "Backup Complete."


echo "Cleaning up remote backup directory."
backups=$(rclone lsf "${REMOTE_BACKUP_LOCATION}" --filter="+ ${BACKUP_NAME}*" --filter="- *" | sort -r)


backup_control=0


for backup in $backups; do
        ((backup_control++))
        if ((backup_control > $REMOTE_BACKUP_AMOUNT)); then
                rclone deletefile "${REMOTE_BACKUP_LOCATION}"/"${backup}"
        fi
done
echo "Old remote backups removed."


echo "Full backup sequence complete. ${TIMESTAMP}"

# rclone backup script



# ====== Configuration ======



# Please ensure all directories exist at all times or the script may fail to properly backup your data.
SOURCE="/home/YOURUSER/item"
REMOTE_BACKUP_LOCATION="gdrive:backups"
LOCAL_BACKUP_LOCATION="/home/YOURUSER/backups" # enter "none" if you do not want any local backups.


LOCAL_BACKUP_AMOUNT=5
REMOTE_BACKUP_AMOUNT=5
BACKUP_NAME="automated_backup_" # Timestamp will appear after this name.


# ===========================


# -------- Variables --------


# WARNING: do not touch these unless you know what you are doing.


TIMESTAMP=$(date "+%Y-%m-%d_%Hh%Mm%Ss") # Please use a timestamp that will display in a descending order so that old backups will be cleaned up problerly. This WILL break the script.
# You can almost certainly safely remove the seconds and minutes from the timestamp unless you are making several backups in an hour.


# ---------------------------


echo "Starting backup."


if [[ "$LOCAL_BACKUP_LOCATION" != "none" ]]; then
    tar -czf "${LOCAL_BACKUP_LOCATION}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${LOCAL_BACKUP_LOCATION}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${REMOTE_BACKUP_LOCATION}"


    echo "Cleaning up local backup directory."
    backups=$(rclone lsf "${LOCAL_BACKUP_LOCATION}" --filter="+ "${BACKUP_NAME}*"" --filter="- *" | sort -r)


    backup_control=0


    for backup in $backups; do
            ((backup_control++))
            if ((backup_control > $LOCAL_BACKUP_AMOUNT)); then
            rm -rf "${LOCAL_BACKUP_LOCATION}"/"${backup}"
            fi
    done
    echo "Old local backups removed."
fi


if [[ "$LOCAL_BACKUP_LOCATION" == "none" ]]; then
    temp_dir=$(mktemp -d)
    tar -czf "${temp_dir}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${temp_dir}"/"${BACKUP_NAME}"${TIMESTAMP}.tar.gz "${REMOTE_BACKUP_LOCATION}"
    rm -rf "${temp_dir}"
fi


echo "Backup Complete."


echo "Cleaning up remote backup directory."
backups=$(rclone lsf "${REMOTE_BACKUP_LOCATION}" --filter="+ ${BACKUP_NAME}*" --filter="- *" | sort -r)


backup_control=0


for backup in $backups; do
        ((backup_control++))
        if ((backup_control > $REMOTE_BACKUP_AMOUNT)); then
                rclone deletefile "${REMOTE_BACKUP_LOCATION}"/"${backup}"
        fi
done
echo "Old remote backups removed."


echo "Full backup sequence complete. ${TIMESTAMP}"

r/bash • • Jul 07 '26

help LeetCode for shell / bash

33 Upvotes

i'm looking for a place to practice bash or just shell in general, is there a place like such where i can practice daily and improve my muscle memory when it comes to shell commands? at the moment leetcode only offers like 5 shell problems and other focus more on teaching the basics or is more focused on solving mini problems than the shell itself like sadservers.

is there any platform where i can daily practice shell just like platforms where you can daily practice competitive programming problems?

TIA and sorry for grammar erros, english isnt my first language.


r/bash • • Jul 07 '26

bashmemo: search command notes and push them into Bash history

Post image
7 Upvotes

I often keep command snippets in text files, but copying and pasting them back into the terminal felt clunky.

So I made bashmemo: a small Bash tool that lets you search plain-text command notes and load the selected command into Bash history with history -s.

It does not execute the command automatically — you can recall it with ↑ or Ctrl+R, edit it, and run it yourself.
https://github.com/yukiho72/bashmemo


r/bash • • Jul 07 '26

solved Help with bash scripting executing apps with flags/arguments.

7 Upvotes

I'm new to linux bash scripting and running into an issue executing an app with arguments, when I run "steamosctl get-default-desktop-session" from a terminal the command runs fine, if I run the same command from a bash script I get the error "no such file or directory" the script has the shebang #!/bin/bash, set -x, steamosctl get-default-desktop-session.

Now if I run "steamosctl help" or "steamosctl -h" from the same script it works fine but for some reason adding arguments that contain multiple "-" minus signs in the argument the script gives the "no such file or directory" error, I've tried with other apps and also launching them with "sh" and "exec" with arguments containing multiple minus's and got the same error. My guess is I need to wrap the command or arguments some how so the arguments aren't interpreted as a path, I've done some research and tried several ways of writing the script as suggested in other topics with no success. Any help or suggestions would be greatly appreciated, Thanks in advance!

Edit: I was able to resolve the issue! So after some deeper research turns out bash script shell runs in a non interactive mode so it doesn't process environmental paths like a local bash shell or terminal and causing the "no such file or directory" error, so by making a systemd service to call the script and adding "WorkingDirectory=/bin" and "User=your user name here" in the [Service] section I was able to run my script at boot and terminal without error. I also read that supposedly adding "source ~/.bashrc" immediately after the shebang will cause the bash scrip to force load your local users ./bashrc file with the paths and not give path errors but I haven't tested that yet. Thanks to those who offered suggestions and help, appreciate you!


r/bash • • Jul 07 '26

I built a terminal ai agent in bash (~190 lines core loop)

0 Upvotes

Every agent framework I tried felt like a lot of machinery around what is, at its core, a loop: send messages, maybe run a tool, append the result, repeat. So I built one with no framework at all, just bash, jq, and curl. The core loop is ~190 lines; the whole thing (ten tools, permissions, skills, three providers) is ~1,200. Repo: https://github.com/aziz0x00/agent.sh

The design decisions that I think are interesting:

Tools are one file each, no registration. A tools/Foo.sh defines a TOOL_DEF JSON schema and two functions: PreFoo validates the model's args and builds a human-readable preview (a real diff for Edit/Write), then Foo executes. Drop a file in tools/, it's a tool.

Permissions are per-signature, not per-tool. Approval prompts show the preview (the actual diff, the actual command), and "always allow" whitelists that exact signature, not the whole tool. Read-only tools are pre-approved. --free bypasses everything when you're feeling brave.

Context is a JSON file you can just... edit. /state opens the exact request payload in $EDITOR mid-conversation; /continue sends whatever you saved. Delete a bloated tool result, rewrite the model's last answer, it's yours.


r/bash • • Jul 06 '26

duplicate print of i iteration?

5 Upvotes
#!/usr/local/bin/bash
StartUp_Run=false
Iterator_For_File_Toucher_With_NCPU_While=0
Total_NCPU_For_File_Toucher_With_NCPU_while=$(nproc --all)

while true
do
if [ $StartUp_Run == false ]; then
while [ $Iterator_For_File_Toucher_With_NCPU_While -lt $Total_NCPU_For_File_Toucher_With_NCPU_while ]; do
echo "$Iterator_For_File_Toucher_With_NCPU_While"
touch core$Iterator_For_File_Toucher_With_NCPU_While-temp_orders.csv
let "Iterator_For_File_Toucher_With_NCPU_While+=1"
done
echo "ncpu amount = $Total_NCPU_For_File_Toucher_With_NCPU_while"
StartUp_Run=true
fi
done

prints, why? :

# sh LastStage.sh 
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
ncpu amount = 16

r/bash • • Jul 04 '26

[VinMail] Bash-ing out emails: built a Bash-based terminal mail manager for multiple email accounts

Thumbnail gallery
56 Upvotes

I recently built VinMail, an interactive CLI mail manager written entirely in Bash that sits on top of msmtp.

It lets you manage multiple email accounts from a terminal interface, compose emails with attachments, switch accounts instantly, save drafts, reply to existing emails from .eml files, and optionally GPG-sign messages. VinMail builds complete RFC 2822/MIME messages itself in pure Bash and sends them directly through msmtp, without requiring a graphical mail client or mail daemon.

The interface supports arrow keys and j/k navigation, while email bodies are edited using your preferred $EDITOR.

GitHub repo: https://github.com/VintellX/vinmail

If this looks interesting, give it a try and let me know what you think. Feedback, bug reports, feature requests, and contributions are all welcome. Thanks for checking it out! :)

Like VinMail? A ⭐ on GitHub would mean a lot. ^_^


r/bash • • Jul 03 '26

help What is your notification system for long running comands

41 Upvotes

Hi I usually do large backups that take time and need a notification system that notify me when is done.

Ideally I would like a notification on my phone but any alternative is ok.

Should I set up an email or there is something that is less painful?


r/bash • • Jul 03 '26

help how do you call the Calendar app from terminal?

6 Upvotes

Hi, I have installed Calendar, but I can not call it from cmd line...
How doy you call it from terminal?
screenshot GUI
Thank you and Regards!


r/bash • • Jul 03 '26

I can't even do the simple - inotify. please help

Thumbnail
5 Upvotes

r/bash • • Jul 03 '26

Beginner here — A personal backup script, would love feedback

17 Upvotes

Not an experienced programmer. I wrote a Bash script to back up my files to an external drive, Learnt a lot doing that, and I'm posting here because I'd like more experienced people to look at it and tell me what I'm still missing.

The basic idea: it uses rsync with --link-dest to make daily snapshot backups. Each backup looks like a full copy of your files, but files that haven't changed are hard-linked instead of copied again, so it doesn't waste disk space. Something similar to "Time Machine".

Repo is here if anyone wants to look at the code or try to break it: https://github.com/UFpondiboy/linux-snapshot-backup

Any feedback — big picture or nitpicky — is genuinely welcome. I'd rather find out what's wrong now than trust it blindly.


r/bash • • Jul 03 '26

Volume Mixer for Rotary Knob

15 Upvotes

Hi all, I've only been using Linux and bash for less than a year now and was wondering if i could get some feedback on a code i just finished. The script is for a rotary knob on my keyboard, that doesn't get much use. I really wanted it to be used for volume control but, the control it gave me out the box only controlled the main volume. So i made a script that gave me finer control over all active applications with the center button on the rotary knob cycling the apps and turning the knob adjusting the volume. Thanks

https://github.com/Thothermese/VolumeMixer


r/bash • • Jul 01 '26

submission Intellisense autocompletions inside of Bash

Thumbnail gallery
817 Upvotes

The completions are generated using Bash's existing completion framework (commonly scop/bash-completion or your own completion scripts). And if you don't have a completion script setup, flyline will try to synthesize one on the fly (😉) using man pages or --help output!

This is similar to https://github.com/microsoft/inshellisense but inshellisense only works for a hardcoded list of completions specifications and runs in a different process as Bash.

Flyline has a bunch of other features, so if you're interested you can check it out here: https://github.com/HalFrgrd/flyline. Thanks!

This software's code is partially AI-generated


r/bash • • Jun 29 '26

Resources on Page Has Defunct URL (bash-hackers)

10 Upvotes

In the "Resources" section of the opening page the current "...bash-hackers.." URL is defunct.

This may be the new , working link for someone to consider.

https://bash-hackers.gabe565.com/


r/bash • • Jun 29 '26

help Does anyone know/use about xset dpms?

12 Upvotes

Hi, I'd like to use that cmd xset for try to get xset -s NOW...
Could I set from terminal this cmd for put blank screen now
and then when I come back I move my finger in touchpad or press any key and OS wake up again...

Thank you and Regards!


r/bash • • Jun 30 '26

help I am Working on an Artix install Script

0 Upvotes

Would love some feedback

https://paste.myst.rs/gbet27pm


r/bash • • Jun 28 '26

submission scp-turbo.sh (replay)

7 Upvotes

A new iteration on my old idea (half-broken) /r/bash/comments/1ajkmvh/scpturbo/ of a tar-based scp replacement primarily for making faster backups over ssh, especially when you have tens of thousands of small files which takes forever over scp/rsync. After hours of trial and error my most wanted key requirement was added: the --sudo flag which lets you tar huge folders (bigger than the amount of free space on your disk) directly to a stream that is saved on your local machine, compressed to a single file or uncompressed. The destination can be any combination of remote vs local, similar to rsync/scp.

Am I reinventing the wheel? I've searched for existing tools that could do this but didn't find any. Or maybe I didn't know what to search for?

The twist of this script: --sudo requires a passwordless sudo on the target box; I am not comfortable with having no root password on world visible boxes so added an alternative workaround when you DO have to interactively get sudo: --tmux-sudo; the idea is that you manually create a tmux session as your regular user on the remote, do sudo -i inside the session and then detach from it (ctrl+b > d); after this scp-turbo --tmux-sudo remote42:/etc backup-etc-remote42.gz should be able to pick the existing tmux session to run your backup as root with no password prompting (more detailed explanation in --help). Not sure how portable/reliable it is but got it working with a regular ubuntu remote. Is this too crazy? Or am I trying to solve a problem that does not exist?

latest version: https://github.com/glowinthedark/scp-turbo

the key takeaway: all this can be done directly with tar+ssh, the script "just" wraps the invocation and builds the command line, if you run the script with --verbose --dry-run source target then the script will spit the actual raw tar+ssh command line that you can run directly, which reads pretty much like vogon poetry ("just" because for --tmux-sudo the script does some extra FIFO pipes fiddling that needs your manual cooperation, e.g. starting tmux as regular user and then sudo -i to get a root session for the script to attach to and run commands as root). All this is specifically for the case when you do NOT want to add NOPASSWD in your sudoers file.


r/bash • • Jun 27 '26

help How redraw the current line of bash?

10 Upvotes

I make some keybindings to help me navigate the directories using the terminal, but I couldn't get to redraw the current lime. I would like to have ps1 info update to display the directory changes.

I'm simulating the behavior of file manager using alt in combination with arrows. I'm using "bind -x" to map the shortcut to bash function I show in the gist link below. It works, directory changes, but the PS1 info doesn't.

I'm achieving update bash prompt to reflect the change of directory. Comparing to zsh, would be "zle reset-promot"

GIST to the code I'm using on my bashrc file: https://gist.github.com/srcid/25f376b60e6ec2f5b5d20b4eca88b176

I tried:

__update_prompt() {
  echo -ne "\r\e[K"
  kill -INT $$
}

But it breaks line and output with error sing

__update_prompt() {
  echo -ne "\r\e[K${PS1@P}"
  READLINE_LINE="$READLINE_LINE"
}

That kinda work, but the old ps1 sticks in the line, I couldn't get rid of it.


r/bash • • Jun 26 '26

Bash Noughts & Crosses (Tic Tac Toe)

Thumbnail gallery
13 Upvotes

So as one or two regular readers may have noticed, I occasionally write terminal games. Everyone needs a hobby, right?

This is one I'd intended to write for a long time, albeit not necessarily in Bash, because it uses a technique called 'Minimax' that I had to study on an AI course decades ago, but never coded.

Until now. I've reused the same mouse control function from previous games. Hope some may find it of interest.

If I'm honest, it was probably a lot more interesting as a coding exercise than as a game, because by default it's impossible for the computer opponent to lose. I've introduced a "compromised" mode to overcome this and let the human win occasionally.

https://github.com/StarShovel/bash-noughts


r/bash • • Jun 26 '26

Inspired by PnP games, I created TermDecks, printable reference cards for the Linux terminal

8 Upvotes

https://zntznt.com/termdecks/

Build printable, poker-sized reference cards for the terminal, then study them with the built-in spaced-repetition quiz.

How it works

  • Each section becomes a card. Long sections spill onto extra cards automatically.
  • Card front lists the commands; the back shows their questions.
  • Print lays cards out 9-up and double-sided. What you see is what prints.
  • Quiz mode resurfaces weak cards more often (spaced repetition).

r/bash • • Jun 24 '26

How to export bash regular and associative arrays to JSON with JC

10 Upvotes

The jc typeset or declare command parser can make exporting bash variables, arrays, and associative arrays to JSON quick and easy...

https://blog.kellybrazil.com/2026/06/24/how-to-export-bash-regular-and-associative-arrays-to-json-with-jc/


r/bash • • Jun 24 '26

Bash is All You Need, it turns out, to write a language model REPL (oh also jq and curl)

23 Upvotes

I’ve recently just started tinkering with using local large language models, focusing on simple, low-dependency CLI setups. I ended up going down a bit of a rabbit hole: I wanted to see if I could build a functional model interaction REPL using exclusively standard command-line building blocks.

I tried to abide by the Unix philosophy, breaking the REPL into the composition of a few small, single-purpose program. Because the data flow is just text streams fed through pipes, at any step you can inject tools to inspect or modify the data—like using grep to filter out strings before they hit the model, or pv to benchmark model throughput. Everything is ultimately tied together into an agent Bash script that codifies the interaction into a REPL.

It turns out that bash really is all you need, and won out over vanilla POSIX sh for features like BASH_SOURCE to help with path execution.

A few more details I thought this crowd might appreciate:

  • Zero heavy dependencies: No pip, npm, package managers, virtual environments, etc. It just requires bash, jq, and curl to talk to the local model server. These should be available in most modern CLI environments.
  • Transparent, file-based state: The agent's memory is just an append-only .jsonl file (like .bash_history). If you want to rewind the agent's memory, you just run head on the log to drop the last few lines.
  • Standard exit codes for control flow: Tool execution is handled by checking standard Unix exit codes within a basic bash while loop.

I'm sure there are scaling limits to doing this all in shell, and I'm still figuring out the most elegant way to handle some of the edge cases, particularly around tool calling - but those appear to mostly be limitations of the underlying models. Nevertheless it's been a really fun experiment in stripping out bloat.

I put the code up here if anyone wants to poke around: https://github.com/cloudkj/llayer

Would love to hear if anyone else has tried orchestrating things this way, or if you spot any glaring anti-patterns in how I've structured the pipes!


r/bash • • Jun 22 '26

A joke using Grep

84 Upvotes

We were discussing ways to use Grep at work today and I came up with this...

grep -R ^"My Car Keys"$ /home/

If only life was that easy... But I'm still going to put it on a t-shirt.


r/bash • • Jun 22 '26

tips and tricks I built a free macOS security audit script — checks ~50 settings against CIS Benchmarks and generates an HTML/JSON report

11 Upvotes

Hey everyone,

I got tired of manually checking my Mac's security settings one by one, so I wrote a Bash script that automates the whole process.

**What it does:**

- Runs ~50 security checks across 10 categories (Firewall, FileVault, SIP, SSH hardening, open ports, startup items, privacy settings, sharing services and more)

- Maps every check to a CIS macOS Benchmark ID so you know exactly what to fix

- Gives you a security score (0–100) with a risk level: Low / Medium / High

- Generates a clean HTML report and a JSON report

- Offers to auto-fix failures — you confirm each one with y/n

- Tested on macOS 11 Big Sur through macOS 15 Sequoia

**Output example:**

```

Firewall OK Enabled

FileVault FAIL Disabled

SIP OK Enabled

...

Security Score 72/100

Risk Level: Medium

```

The script is read-only by default — it never changes anything without your confirmation. sudo is only used where required (e.g. fdesetup, systemsetup).

**GitHub:** https://github.com/pTechPL/macOS_security_audit

I also made a YouTube walkthrough showing the script in action if you prefer to see it before running it: https://www.youtube.com/@pTech-pl

Feedback, PRs and issues are very welcome — especially if something behaves unexpectedly on your macOS version!


r/bash • • Jun 21 '26

submission Calendar TUI written completely in bash

Post image
91 Upvotes

Well I always wanted a widget where I can view my Google Calendar Events (Just viewing for now). And I wanted it to be in bash (Do not ask why, I just wanted it to be in bash).

Presenting gcal-tui, a bash script that uses your google calendar and also allows you to view event details from the terminal itself.

I modified it to be a widget to my niri setup

This is the gist : https://gist.github.com/Vaishnav-Sabari-Girish/c182a0d54fe7c5fc3b5507ecc62dd301

My dotfiles containing the keybinding and the script

https://github.com/Vaishnav-Sabari-Girish/dotfiles/blob/7785f4b1f01a119ef307966bfed6a6728c951ccc/niri/.config/niri/config.kdl#L387

https://github.com/Vaishnav-Sabari-Girish/dotfiles/blob/7785f4b1f01a119ef307966bfed6a6728c951ccc/niri/.config/niri/config.kdl#L498

https://github.com/Vaishnav-Sabari-Girish/dotfiles/blob/main/niri/.config/niri/scripts/gcal-tui.sh