//View Tip #145
Similar Tips
» List non-system users
» Close shell keeping all subprocess running
» another solution to #67
» Overwrite a file with zeroes
» Version all unversioned files in an SVN checkout

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
# Swap 2 files/dirs that are in the same dir
# Usage: sw f1 f2
function sw {
f1=$1
f2=$2
if [ "x$f2" = "x" ]; then
echo "Usage: sw file1 file2"
echo " swap name of 2 files"
else
d1=$(dirname $f1)
d2=$(dirname $f2)
if [ "$d1" != "." -o "$d2" != "." ]; then
echo "sw: Can swap only files in current directory"
else
if [ -e "$f1" -a -e "$f2" ]; then
mv $f1 .sw.$f1
mv $f2 $f1
mv .sw.$f1 $f2
else
echo "sw: '$f1' and '$f2' must exist"
fi
fi
fi
}


View Comments »




Comments 

Add your comment

Comments are currently disabled
No Comments

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit