mvln 移动并软链接

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

mvln 移动并软链接

#1

帖子 eexpress » 2013-09-24 10:49

git 可能经常用到。

代码: 全选

● cat mvln.bash 
#!/bin/bash

u="mv Source Destine; ln -sf Destine Source"
[ -z "$1" ] && echo $u && exit
[ ! -f "$1" ] && echo "first argument need regular file." && exit
s=`readlink -f "$1"`

if [ -d "$2" ]; then
	d=`readlink -f "$2"`/`basename "$1"`
else
	if [ -e "$2" ]; then
		echo "second argument is exist file."
		exit
	else
		d=`dirname "$2"`
		if [ -d "$d" ]; then
			d=`readlink -f "$2"`
		else
			echo "directory $d not exists."
			exit
		fi
	fi
fi

echo "-----------------------"
echo "Source: $s"
echo "Destine: $d"
echo "-----------------------"
echo $u
echo "if confirm press [enter]. other key cancel."
read -s -n 1 y
if [[ $y == '' ]]; then
echo -e "\e[1;32mdone.\e[0m"
mv "$s" "$d"
ln -sf "$d" "$s"
ls -l --color "$s" "$d"
else
echo -e "\e[1;31mcancel.\e[0m"
fi
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: mvln 移动并软链接

#2

帖子 eexpress » 2013-09-24 10:52

代码: 全选

2013-09-24 10:51:11 二 ~/.macromedia/Flash_Player/#SharedObjects/GN6WPFM8/#localWithNet/eexp/Yunio/kingdom-rush/kingdom-rush-v1.1-cn.swf 
● mvln.bash krslot1.sol ~/Yunio/kingdom-rush/
-----------------------
Source: /home/eexp/.macromedia/Flash_Player/#SharedObjects/GN6WPFM8/#localWithNet/eexp/Yunio/kingdom-rush/kingdom-rush-v1.1-cn.swf/krslot1.sol
Destine: /home/eexp/Yunio/kingdom-rush/krslot1.sol
-----------------------
mv Source Destine; ln -sf Destine Source
if confirm press [enter]. other key cancel.
done.
lrwxrwxrwx 1 eexp eexp   41  9月 24 10:51 /home/eexp/.macromedia/Flash_Player/#SharedObjects/GN6WPFM8/#localWithNet/eexp/Yunio/kingdom-rush/kingdom-rush-v1.1-cn.swf/krslot1.sol -> /home/eexp/Yunio/kingdom-rush/krslot1.sol
-rw-rw-r-- 1 eexp eexp 4958  9月 24 09:25 /home/eexp/Yunio/kingdom-rush/krslot1.sol
● 鸣学
回复