Skip to content

Instantly share code, notes, and snippets.

@seansaito
Last active May 18, 2020 14:36
Show Gist options
  • Select an option

  • Save seansaito/395457091cbb9b745f61d546dec80a03 to your computer and use it in GitHub Desktop.

Select an option

Save seansaito/395457091cbb9b745f61d546dec80a03 to your computer and use it in GitHub Desktop.
Remove tmux sessions older than a specific date
#!/bin/bash
# Usage: ./rm_tmux.sh 2020-01-01
tmux ls | tr -d '()' | awk -v dateA=$1 '{
cmd ="date \"+%Y-%m-%d\" -d \""$6" "$7" "$8" "$9"\""
cmd | getline dd
if (FNR>1 && dd<=dateA) {
print $1
}
close(cmd)
}' | tr -d ':' | while read line
do
echo "killing $line"
tmux kill-session -t $line
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment