[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Removing backup files corresponding to no longer existing files
From: |
Pascal J. Bourguignon |
Subject: |
Re: Removing backup files corresponding to no longer existing files |
Date: |
Tue, 24 May 2011 20:02:04 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Rasmus Villemoes <burner+usenet@imf.au.dk> writes:
> Hi,
>
> I use a couple of separate directories to store emacs backup files
> (using backup-directory-alist). But this means that if I decide to
> delete or move some project (which is in its own direcory), just
> deleting or moving the directory leaves all the backup copies
> behind. They will then stay in the backup directories forever.
>
> Is there a way to tell emacs to remove backup files which no longer
> correspond to an actual file?
>
> It's probably not very difficult to write a little (shell/perl) script
> to do this, but I was wondering if there is some builtin way which
> I've overlooked.
>
> Emacs 23.1.1 on Ubuntu 10.10, if it matters.
I have:
-----(clean-old-versions)-----------------------------------------------
#!/bin/bash
dirs=()
do=
for arg ; do
case "$arg" in
-n) do=echo ;;
-*) echo "Usage:"
echo " $(basename $0) [-n] [directory ...]"
echo "Remove all backup files that don't have a head."
echo "If no directory is specified, then clean the current directory."
echo "-n only shows what would be done."
exit 1
;;
*) dirs[${#dirs}]="$arg" ;;
esac
done
if [ ${#dirs[@]} -eq 0 ] ; then
dirs=(.)
fi
for dir in "${dirs[@]}" ; do
find "$dir" -maxdepth 1 \( -name \*~ -o -name .\?\*~ \) -print \
|while read file ; do
base="$(echo "$file" | sed -e 's/\(\.~[.0-9]\+\)\?~$//')"
if [ ! -e "$base" ] ; then
$do rm -v "$file"
fi
done
done
------------------------------------------------------------------------
Indeed, it wouldn't be too hard to write it in emacs lisp either.
The question would be when to run it?
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.