【转载】设计自己的文件系统_之一 - [Linux内核]

转载自http://kernel-of-linux.blogbus.com/logs/15569454.html

首先先编写这样一个SHELL程序,目的:把当前目录下的所有文件中的“EXT2”都改为“MYEXT2”。

在/home/xs的目录下建立substitute.sh

#mkdir xs

#cd xs

#touch substitute.sh

# vi substitute.sh

OK,现在已经进入到/home/xs(自己建立的用户目录)/substitute.sh文件中。

输入源码

#!/bin/sh

SCRIPT=substitute.sh

for f in * ;

do

    if [ $f = $SCRIPT ] ; then

        echo "skip $f"

        continue

    fi

echo -n "substitute ext2 to myext2 in $f..."

cat $f | sed 's/ext2/myext2/g'>${f}_tmp

mv ${f}_tmp $f

echo "done"

echo -n "substitute EXT2 to MYEXT2 in $f..."

cat $f | sed 's/EXT2/MYEXT2/g'>${f}_tmp

mv ${f}_tmp $f

echo "done"

done

源码完毕!保存退出。

最后,看看程序的效果,例如建立一个文件hello.c,现在可以把hello.c中所有的ext2和EXT2改为myext和

MYEXT2

posted @ 2011-01-11 02:58  羽落无声  阅读(545)  评论(0编辑  收藏  举报