Re: [OFFTOPIC] Hardlink utility - reclaim drive space

David Schleef (ds@schleef.org)
Mon, 5 Mar 2001 14:08:18 -0800


--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Mar 05, 2001 at 07:17:18PM +0000, Padraig Brady wrote:
> Hmm.. useful until you actually want to modify a linked file,
> but then your modifying the file in all "merged" trees.

Use emacs, because you can configure it to do something
appropriate with linked files. But for those of us addicted
to vi, the attached wrapper script is pretty cool, too.

dave...

--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=cow-wrapper

#!/bin/bash
#
# copy-on-write wrapper for hard linked files
# Copyright 2000 David A. Schleef <ds@schleef.org>
#
# Please send me any improvments you make to this script. I just
# wrote it as a quick and dirty hack.

linkedfiles=

for each in $*
do
case $each in
-*)
# ignore
;;
*)
if [ -f "$each" ];then
nlinks=$(stat $each|grep Links|sed 's/.*Links: \(.*\)\{1\}/\1/')
if [ $nlinks -gt 1 ];then
#echo unlinking $each
linkedfiles="$linkedfiles $each"
mv $each $each.orig
cp $each.orig $each
fi
fi
;;
esac
done

/usr/bin/vim $*

for each in $linkedfiles
do
if cmp $each $each.orig &>/dev/null
then
#echo relinking $each
rm $each
mv $each.orig $each
fi
done

--Q68bSM7Ycu6FN28Q--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/