all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Removing backup files corresponding to no longer existing files
Date: Sun, 08 May 2011 17:20:07 +0200	[thread overview]
Message-ID: <87hb95rzh4.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: u0lmxix8wty.fsf@orc05.imf.au.dk

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 {}.


  reply	other threads:[~2011-05-08 15:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-08  7:39 Removing backup files corresponding to no longer existing files Rasmus Villemoes
2011-05-08 15:20 ` Pascal J. Bourguignon [this message]
2011-05-09 21:49   ` Rasmus Villemoes
2011-05-24 20:35 ` Deniz Dogan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hb95rzh4.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.