1、简单测试实例

 for i in `find . -type f -name "*.c"`
do
  echo $i
  basename $i    获取*.c文件名
  dirname $i        获取*.c对应的目录名
done


2、实际应用

diff Linux源码,并将有不一样的源码整理在一起,要求:文件名以new和old区分。

(1)、简单测试


rm -rf ~/Desktop/20091107

cp_source()
{
#for i in `find . -type d -print`
for i in `find $1 -type f -name "*.s"`
do
  #echo $i
  #basename $i
  dirname $i

  mkdir -p ~/Desktop/20091107/`dirname $i`
  cp $i ~/Desktop/20091107/`dirname $i`/`basename $i`_"$2"
done
}

cd linux-0.11 && cp_source "." "new"
cd ../linux-0.11 && cp_source "." "old"

 

(2)、实际实现(以diff -Nur linux-2.6.30 linux-2.6.31.5为例)

 

rm -rf ~/Desktop/20091107

#cat linux-patch.txt | grep 'diff -Nur ' | sed 's/^.*linux-2.6.30g'| sed 's/ linux-2.6.31.5.*$//g' > ~/Desktop/diff.txt

old_source_noprefix=`cat linux-patch.txt | grep 'diff -Nur ' | sed 's/^.*linux-2.6.30g'| sed 's/ linux-2.6.31.5.*$//g'`
new_source_noprefix=`cat linux-patch.txt | grep 'diff -Nur ' | sed 's/^.*linux-2.6.31.5g'`

old_source_haveprefix=`cat linux-patch.txt | grep 'diff -Nur ' | sed 's/^.*linux-2.6.30/linux-2.6.30/g'| sed 's/ linux-2.6.31.5.*$//g'`
new_source_haveprefix=`cat linux-patch.txt | grep 'diff -Nur ' | sed 's/^.*linux-2.6.31.5/linux-2.6.31.5/g'`

cp_source()
{
#for i in `find . -type d -print`
for i in $1
do
  #echo $i

  #basename $i
  #dirname $i
 
  #Used "diff -Nur", some file didn't exist!
  mkdir -p ~/Desktop/20091107/`dirname $i` && cp ./$2/$i ~/Desktop/20091107/`dirname $i`/`basename $i`_"$3" 2>/dev/null
done
}

cp_source "$old_source_noprefix" "linux-2.6.30" "old"
cp_source "$new_source_noprefix" "linux-2.6.31.5" "new"


GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐