This is exactly the kind of stuff I'm most interested in finding on HN. How do other developers work, and how can I get better at my work from it? What's always interesting to me is how many of these I'll see and initially think, "I don't really need that." Because I'm well aware of the effect (which I'm sure has a name - I suppose it's similar to induced demand) of "make $uncommon_task much cheaper" -> "$uncommon_ta…
Scripts I wrote that I use all the time
351–360 of 408 posts
Re: Scripts I wrote that I use all the time
#352I keep meaning to generalize this (directory target, multiple sources, flags), but I get quite a bit of mileage out of this `unmv` script even as it is: #!/bin/sh if test "$#" != 2 then echo 'Error: unmv must have exactly 2 arguments' exit 1 fi exec mv "$2" "$1"
Re: Scripts I wrote that I use all the time
#353Re: Scripts I wrote that I use all the time
#354My fav script to unpack anything, found a few years ago somewhere # ex - archive extractor # usage: ex function ex() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.tar.xz) tar xf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' can…
Re: Scripts I wrote that I use all the time
#355I have a bunch of little scripts and aliases I've written over the years, but none are used more than these... alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias .......='cd ../../../../../..'
Re: Scripts I wrote that I use all the time
#356> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux. The way you’re doing it trashes files sequentially, meaning you hear the trashing sound once per file and ⌘Z in the Finder will only restore the last one. You can improve that (I did it for years) but consider just using the `trash` commands which ships with macOS. Doesn’t use the Finder, so no sound and no ⌘Z, but it’s fast, offici…
% cat /proc/sys/kernel/random/uuid
464a4e91-5ce4-47b6-bb09-8a60fde572fbRe: Scripts I wrote that I use all the time
#357One script I use quite often: function unix() { if [ $# -gt 0 ]; then echo "Arg: $(date -r "$1")" fi echo "Now: $(date) - $(date +%s)" } Prints the current date as UNIX timestamp. If you provide a UNIX timestamp as arg, it prints the arg as human readable date.
epoch () {
if [[ -z "${1:-}" ]]
then
date +'%s'
else
date --date="@${1}"
fi
}
% epoch
1761245789
% epoch 1761245789
Thu Oct 23 11:56:29 PDT 2025Re: Scripts I wrote that I use all the time
#358I have a bunch of little scripts and aliases I've written over the years, but none are used more than these... alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias .......='cd ../../../../../..'
fish lets you cd to a folder without 'cd' although you still need the slashes. I use it all the time. c $> pwd /a/b/c c $> dir1 dir1 $> .. c $> ../.. / $>
Re: Scripts I wrote that I use all the time
#359> alphabet just prints the English alphabet in upper and lowercase. I use this surprisingly often (probably about once a month) I genuinely wonder, why would anyone want to use this, often?
As a programmer, you sometimes want to make an alphabet lookup table. So, something like: var alpha_lu = "abcdefghijklmnopqrstuvwxyz"; Typing it out by hand is error prone as it's not easy to see if you've swapped the order or missed a character. I've needed the alphabet string or lookup rarely, but I have needed it before. Some applications could include making your own UUID function, making a small random naming sc…