ºìÁªLinuxÃÅ»§
Linux°ïÖú

Shell½Å±¾ÊµÏÖvi/cp/mvÇ°×Ô¶¯±¸·ÝÔ´Îļþ

·¢²¼Ê±¼ä:2007-08-29 00:01:30À´Ô´:ºìÁª×÷Õß:hearer
ÒÔϽű¾°ÑËùÓÐÒª±à¼­µÄÔ´Îļþ±¸·Ýµ½/bakĿ¼Ï£¬²¢ÇÒËùÓеÄ·¾¶Î»Öñ£³Ö²»±ä£¬±ÈÈçvii /etc/hosts£¬Ôò°Ñ/etc/hosts¸´ÖƵ½/bak/etc/hosts¡£

# cat /sh/vii

#!/usr/bin/bash

#ÅжÏÔ´ÎļþÊÇ·ñ´æÔÚ£¬´æÔÚ²ÅÖ´Ðб¸·Ý²Ù×÷

if [ -f "$1" ];then

#´´½¨º¯Êý£¬¿ÉʵÏÖÈÎÒâ¼ü¼ÌÐø

#Èç¹ûÄãµÄ»úÆ÷Éϲ»ÈÏstty rawÄÇô°Ñº¯ÊýÖÐÁ½´¦³öÏÖµÄraw»»³Écbreak

get_char()

{

SAVEDSTTY=`stty -g`

stty -echo

stty raw

dd if=/dev/tty bs=1 count=1 2> /dev/null

stty -raw

stty echo

stty $SAVEDSTTY

}

#´´½¨±¸·ÝµÄ¸ù·¾¶/bak,²¢ÈÃËùÓÐÈ˾ßÓÐдȨÏÞ

if [ ! -d "/bak" ];then

mkdir /bak

chmod a+w /bak

fi

#ÅжÏÄ¿±êÎļþËù´¦µÄ·¾¶²¢´´½¨£¬ÈÃËùÓÐÈ˶Ôд´½¨µÄÈÎÒ»¼¶Ä¿Â¼¾ù¾ßÓÐдȨÏÞ

echo $1 | grep "/" >/dev/null

if [ "`echo $?`" = "0" ];then

cd ${1%/*}

fi

pwdnow=`pwd`

path=/bak${pwdnow}

#echo $path

if [ ! -d "$path" ];then

mkdir -p $path

patha=${pwdnow#/}

chmod -R a+w /bak/${patha%%/*}

fi

#¸´ÖÆÄ¿±êÎļþ

datenow=`date +%Y%m%d`

timenow=`date +%H%M%S`

/usr/bin/cp $1 ${path}/${1##*/}.${datenow}.${timenow}

echo "Target file \"$1\"

has been copied to ${path}/${1##*/}.${datenow}.${timenow}"

echo "Now going to \"vi $1\",Press any key to continue..."

char=`get_char`

fi

#µ÷ÓÃviÃüÁî

vi $1

µ÷Óýű¾

# chmod a+x /sh/vii

# /sh/vii /etc/passwd

Äã¿ÉÒÔ°Ñ/sh¼ÓÈëµ½PATH±äÁ¿ÖУ¬ÕâÑù¾Í¸ü·½±ãÁË¡£

ͬÀí£¬Éæ¼°cp/mvÃüÁîʱ×îºÃÒ²±¸·ÝÒ»ÏÂÄ¿±êÎļþ£¬ÒÔÃâ±»ÒâÍ⸲¸Ç¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ