Posts by BashSnippets

@BashSnippets

BashSnippets

Building a free bash script library. One script at a time | https://bashsnippets...
North America bashsnippets.xyz Joined May 2026
3.8k Points • 142 Badges • 14 Connections • 17 Followers • 34 Following

Posts by BashSnippets

BashSnippets • • in Articles • 1 min read
The reflex when /etc says no is to put sudo in front. From a script: $ sudo echo "maxconn=200" > /etc/demo.conf pd.sh: line 2: /etc/demo.conf: Permission denied exit=1 $ echo "maxconn=200" | sudo -n tee /etc/demo.conf sudo: a password is required ex...
post-cover-33583
BashSnippets • • in Articles • 1 min read
Five lines whose only job is to refuse a deploy when the token is missing. Run with the token unset: $ cat deploy-guard.sh !/bin/bash if -n $DEPLOYTOKEN ; then echo "token present, deploying" else echo "no token, refusing" >&2; exit 1 fi $ env ...
post-cover-33582
BashSnippets • • in Articles • 1 min read
rm -rf "$TARGET/" looks correct. The quotes are right and the glob sits outside them, where it has to. I put it in a two-line script in a scratch directory and asked what happens when TARGET is empty, with echo in front so rm never ran: the command l...
post-cover-29100
BashSnippets • • in Articles • 1 min read
A four-line cleanup script, cd /srv/drop, rm .log, echo "cleanup done", run on a scratch tmpfs. At 80,290 files it emptied the directory. At 80,291: $ /srv/cleanup.sh /srv/cleanup.sh: line 4: /usr/bin/rm: Argument list too long cleanup done exit=0 $...
post-cover-30659
BashSnippets • • in Articles • 1 min read
Two rsync commands one character apart both exit 0 and put the same file in different places. I ran them side by side in a scratch directory, rsync 3.5.0, with one file at projects/app/main.sh: $ rsync -a projects backup-a/ $ find backup-a -type f b...
post-cover-29099
BashSnippets • • in Articles • 1 min read
On August 6 my laptop booted to a blank terminal. lightdm has Restart=always, and systemctl status said active running. Xorg had entered the NVIDIA init about 140 ms before the device nodes existed and hung there for fourteen hours: state S, 20 ms of...
post-cover-29098
BashSnippets • • in Articles • 1 min read
My dev server came up on 3001 for months because something had 3000. As a normal user, ss -ltnp 'sport = :3000' showed two rows, 0.0.0.0:3000 and :::3000, with nothing under Process. I had seen output like that before and moved on. Run back through ...
post-cover-30658
BashSnippets • • in Articles • 1 min read
On August 28 my laptop sat at 88 % disk. I deleted a 44.6 GB video intermediate I could rebuild any time. du on the folder dropped 44 GB. df on the filesystem moved 5. XFCE's thumbnailer, tumblerd, still had the file open, and a deleted file's blocks...
post-cover-29097
BashSnippets • • in Articles • 1 min read
EADDRINUSE right after you stopped the server usually has one cause: the process you launched is not the process holding the socket. I reproduced it on my own machine with the wrapper shape npm run dev uses, a shell that starts the real server as a c...
post-cover-29095
BashSnippets • • in Articles • 1 min read
Setting up SSH keys has a trap: every success signal can be green while the thing you cared about stays broken. ssh-copy-id exiting 0 means a line was appended to authorizedkeys — nothing more. A passwordless login afterwards means some auth method w...
post-cover-28029
BashSnippets • • in Articles • 1 min read
A world-writable file can be rewritten by every account on the machine — including the service account your web server runs as. Code executing as www-data through a compromised plugin doesn't need root: any chmod 777 you left behind during past debug...
post-cover-28028
BashSnippets • • in Articles • 1 min read
A 64M scratch tmpfs, a worker process holding its log open on file descriptor 3, and the usual reflex when space runs low: rm the log. du on the directory dropped from 48M to 0. df stayed at 48M used. The next 32M write failed with No space left on d...
post-cover-30657
BashSnippets • • in Articles • 1 min read
Most "the filter looks right but the script misbehaves" bugs come down to three silent failure modes. First, a missing -r. jq outputs JSON by default, so a string arrives with its quotes attached — your variable holds "web-01", quotes included, and ...
post-cover-28027
BashSnippets • • in Articles • 1 min read
If grep returns empty on a file you know contains matches, suspect the pattern before the file. Default grep uses Basic Regular Expressions BRE, where |, +, ?, and are literal characters unless backslash-escaped. So grep "error|failed" app.log searc...
post-cover-28026
BashSnippets • • in Articles • 1 min read
A demo script called report, two directories on PATH, and one mv between them, all on a scratch tmpfs: $ report report 2.1: 14 jobs ok exit=0 $ mv /opt/jobs/bin/report /opt/jobs/newbin/report $ ls -l /opt/jobs/newbin/report rwxrwxr-x 1 root root 42 ...
post-cover-30653
BashSnippets • • in Articles • 1 min read
The trap with rsync is that its dangerous flag combinations don't fail — they complete a different operation than the one you intended, and exit 0. --delete makes the destination match the source, so a mistyped or freshly moved source directory means...
post-cover-28025
BashSnippets • • in Articles • 1 min read
The standard bash alerting pattern ends the same way everywhere you read it: pipe the finding into mail. So I checked what my own box would actually do with that line. $ type -a mail mailx sendmail mail not found mailx not found sendmail not found ...
post-cover-28024
BashSnippets • • in Articles • 1 min read
I wrote four lines to capture a bash error for a guide. One empty variable, tested twice: $ cat queue-check.sh !/bin/bash count="" if $count -eq 0 ; then echo "queue empty"; fi if $count -eq 0 ; then echo "queue empty "; fi $ bash queue-check.sh...
post-cover-29670
BashSnippets • • in Articles • 1 min read
Four config files, one hostname to rename. I knew the dot in api.internal is a regex wildcard, so I escaped it. grep -rn 'api.internal' unescaped matched a fourth file containing apiXinternal — a typo somebody deliberately kept. Escaped, api\.interna...
post-cover-28023
BashSnippets • • in Articles • 1 min read
I set three log files to known ages with touch -d — exactly 30 days, 30 days and 12 hours, and 31 days — then ran what I thought was a 30-day retention policy: find . -name '.log' -mtime +30 It returned one file: the 31-day-old one. The 30.5-day f...
post-cover-28022
chevron_left