Skip to content

Instantly share code, notes, and snippets.

@wieczorek1990
Last active August 29, 2015 14:07
Show Gist options
  • Save wieczorek1990/f29b3aeb7c132c51a8fd to your computer and use it in GitHub Desktop.
Save wieczorek1990/f29b3aeb7c132c51a8fd to your computer and use it in GitHub Desktop.
Safe symbolic links removal
#!/bin/bash
# Useful when using `set mark-symlinked-directories on` in inputrc
# Install trash-cli first or replace `trash` with `rm -rf`
r() {
for arg
do
s=${#arg}
arg2=${arg:0:s-1}
if [ -L "$arg2" ]
then
if [[ "${arg: -1}" == '/' && -d "$arg" ]]
then
echo "Preserving symlinked directory '$arg'"
fi
else
trash "${arg}"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment