SaveSnippets
Community
Pricing
Sign In
Get Started
Community
Public Snippets
11
Code shared by the SaveSnippets community — browse, copy, and get inspired.
All Languages
Bash
Go
HTML
Java
JavaScript
Kotlin
PHP
Python
Rust
SQL
TypeScript
#sysadmin
Clear
Tags
#php
#kotlin
#bash
#go
#sql
#rust
#typescript
#html
#java
#python
#files
#utils
#strings
#http
#concurrency
#async
#json
#arrays
#security
#types
#crypto
#database
#dates
#format
Bash
Find Largest Files and Directories
Quick "where did all my disk go?" answer. du sorts by size, ncdu (interactive) is better for exploration.
#bash
#sysadmin
#disk
#du
#find
Bash
Memory / CPU / Load Quick Check
One-liners for the three most-requested system metrics. Use in monitoring scripts or as ad-hoc sanity checks.
#bash
#sysadmin
#memory
#cpu
#load
Bash
Generate a Random Password
Three approaches: pwgen (purpose-built), openssl (universally available), /dev/urandom + tr (zero deps). Pick by what's installed.
#bash
#sysadmin
#random
#password
#openssl
Bash
Check Systemd Service Is Running
`systemctl is-active` is the right tool — exit code 0 if running, non-zero otherwise. Combine with restart-on-fail for poor-man's supervision.
#bash
#sysadmin
#systemd
#systemctl
#journalctl
Bash
Tar Archive with Timestamp
Pack up a directory with a date-stamped filename for easy backups. -z for gzip, -j for bzip2, -J for xz (smallest, slowest).
#bash
#sysadmin
#tar
#backup
Bash
Disk Space Alert
Cron-friendly script that checks disk usage on each filesystem and emails (or webhooks) if any partition exceeds a threshold.
#bash
#sysadmin
#disk
#df
#alert
Bash
Cron Entry From Script
Append a cron job idempotently — grep first to avoid duplicates on re-run. Doesn't require editing files manually.
#bash
#sysadmin
#cron
#crontab
Bash
OS / Distro Detection
Read /etc/os-release for distro info — it's the standard on every modern Linux. Branch deploy scripts on distro to pick apt vs. dnf vs. apk.
#bash
#sysadmin
#distro
#os-release
Bash
Detect Whether Running as Root
Several scripts must run as root (or refuse to). EUID is more reliable than `whoami == root` because sudo without -E may change one but not the other.
#bash
#sysadmin
#root
#sudo
Bash
Rotate Logs Manually
If a service doesn't hook into logrotate, you can still rotate a log file yourself in one safe pattern: rename current → .1, truncate the original, signal the process to re-open if needed.
#bash
#sysadmin
#logs
#rotation
Bash
Create User With Sensible Defaults
Provision a new user account with a home directory, default shell, and sudo membership. Idempotent — re-running on an existing user is a no-op.
#bash
#sysadmin
#user
#useradd
#ssh