Created
June 6, 2018 08:39
-
-
Save Da-Juan/a9cd992f1dd9700632f3c5e800c3acb5 to your computer and use it in GitHub Desktop.
Remove all files except some
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Enable Extended Globbing | |
shopt -s extglob | |
# Simple version | |
rm !(a|b|c) | |
# Scriptable version | |
function join_by { | |
local IFS="$1" | |
shift | |
echo "$*" | |
} | |
KEEP=( "a" "b" "c" ) | |
rm !($(join_by "|" "${KEEP[@]}")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment