linux:bash
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:bash [2023-09-25 20:31] – [.inputrc] dave | linux:bash [2023-09-25 20:44] (current) – [Bash] dave | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Bash ====== | ====== Bash ====== | ||
| - | FIXME: This isn't really bash, it's random Linux stuff that I'm tired of looking | + | Bash stuff that I'm tired of looking |
| - | ===== HowTo ===== | ||
| - | Find the subnet given IP and mask or CIDR | ||
| - | < | ||
| - | 172.16.16.112/ | ||
| - | This assumes you have [[https:// | ||
| - | |||
| - | Pad an IP to make it sortable | ||
| - | < | ||
| - | 172.016.016.112/ | ||
| - | |||
| - | ===== Date ===== | ||
| - | My preferred date/time format is ISO 8601. | ||
| - | < | ||
| - | Can also be accomplished with... | ||
| - | < | ||
| - | Specific timezone and 3 hours in the future... | ||
| - | < | ||
| ===== Command Substitution ===== | ===== Command Substitution ===== | ||
| Line 39: | Line 22: | ||
| - | ===== find ===== | ||
| - | I never remember how to find old files... either of these will work. The second one uses minutes (I don't know why you'd want to) and shows how to exclude files. | ||
| - | find DIR -name " | ||
| - | find . ! -name ' | ||
| - | Add this to the end and anything that matches will be deleted. | + | ===== Detect if Script is Run by Cron ===== |
| + | # Check if script is cron or shell - two versions. | ||
| + | * [[https:// | ||
| < | < | ||
| - | -exec rm -f {} \; | ||
| - | </ | ||
| - | |||
| - | Limit depth to current directory. | ||
| - | < | ||
| - | find . -maxdepth 1 -name " | ||
| - | </ | ||
| - | |||
| - | ===== Sort These ===== | ||
| - | < | ||
| - | # to delete empty dirs | ||
| - | find -type d -empty -delete | ||
| - | |||
| - | # to delete files over some age & empty dirs | ||
| - | find /some/path -depth \( \( -type f -daystart -mtime +100 \) -o -type d -empty \) -ls | ||
| - | |||
| - | ======================= | ||
| - | # Check if script is cron or shell | ||
| - | https:// | ||
| if [ -t 1 ] ; then | if [ -t 1 ] ; then | ||
| echo " | echo " | ||
| Line 70: | Line 32: | ||
| #send mail | #send mail | ||
| fi | fi | ||
| + | </ | ||
| - | ----------------------- | + | < |
| CRON=$(pstree -s $$ | grep -q cron && echo true || echo false) | CRON=$(pstree -s $$ | grep -q cron && echo true || echo false) | ||
| then test with | then test with | ||
| Line 81: | Line 44: | ||
| echo "Not being run by cron" | echo "Not being run by cron" | ||
| fi | fi | ||
| - | ======================= | ||
| </ | </ | ||
linux/bash.1695673890.txt.gz · Last modified: by dave
