Skip to content

Instantly share code, notes, and snippets.

@agateau
Created March 31, 2015 07:50
Show Gist options
  • Save agateau/1cec7aba565694e80899 to your computer and use it in GitHub Desktop.
Save agateau/1cec7aba565694e80899 to your computer and use it in GitHub Desktop.
Check if files can be safely removed, according to lsof
#!/bin/sh
set -e
can_be_removed=""
keep=""
for x in * ; do
if [ ! -f "$x" ] ; then
continue
fi
if lsof "$x" > /dev/null ; then
keep="$keep\n$x"
else
can_be_removed="$can_be_removed\n$x"
fi
done
echo "# Can be removed"
echo $can_be_removed
echo
echo "# Don't touch!"
echo $keep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment