Archive for the 'BASH' Category

两个find命令

星期三, 01月 7th, 2009

1. find ./ -iname “*.bid” -exec cp  {} bid/ \;

将目录下所有匹配的文件copy到一个目录下,不包含路径。

或:find ./ -iname “*.bid” -exec cp  -t  bid/ {} +

2.find ./ -iname “*.bid” -exec tar cvzf bids.tar.gz  {} +
将目录下所有匹配的文件打包,包含对应的路径。

http://forum.ubuntu.org.cn/viewtopic.php?f=21&t=108619

解析图书馆电影地址脚本

星期日, 05月 11th, 2008

pjq@localhost ~/shell/movies $ cat dmlist.sh
#!/bin/bash
#this shell is used to get the real URL of the movie on :http://210.29.99.11:6666
#
mkdir -p “/tmp/movie”
tmp=”/tmp/movie”
echo $tmp
wget -O ${tmp}/htm “http://210.29.99.11:6666/view/list.exl”
page_number=`cat ${tmp}/htm|iconv -c -f gb2312 -t utf8|grep “共有”|cut -d “&” -f1|cut -d “:” -f3|sed ’s/页//’ `
let page_number=$page_number
echo “the total number of web is: $page_number ”
let i=1
#i refers to the number of the web
while [ $i -lt ${page_number} ];do
echo “starting downloading page:$i”
wget -O “${tmp}/movie” “http://210.29.99.11:6666/view/list.exl?page=${i}”
((i++))
iconv -c -f gb2312 -t utf8 “${tmp}/movie” >>”${tmp}/movie-utf8″
done

cat “${tmp}/movie-utf8″ |grep “value”|awk -F ” value=\”" ‘{print $2}’|awk -F “\”><img src=” ‘{print $1}’|grep -v “>” >movie.list

rm -r “${tmp}”
包含脚本和解析的电影地址

一个查看天气的脚本(修改自“大骨头”的)

星期日, 01月 6th, 2008

点这里下载:weathertar.gz

./weather

然后直接输入城市名字

比如:上海

就行了

#!/bin/bash
#Copyright (c) 2007 bones7456 (bones7456@gmail.com)
#edited by percy(pengjianqing@sina.com)1/5/2007
#License: GPLv3
echo “please keyin the city code”
echo -n “city:”
read city
city=`grep “$city” ./city.txt |cut -d “-” -f1`
#城市代码,留空可自动检测(自动检测不一定精确),城市代码可在 http://weather.265.com 上查询,是个5位的数字
#city=

if [ -n "$city" ] ;then
wid=${city}
else
wget -q -O /tmp/weather.html ‘http://weather.265.com/get_weather.php?action=get_city’;
wid=`iconv -f gbk -t utf8 /tmp/weather.html | grep ‘wid_265=’ | sed -e ’s/document\.cookie\ =\ “wid_265=//’ | sed -e ’s/”.*//g’`;
fi
#echo “wid=${wid}”
wget -q -O /tmp/weather.html “http://weather.265.com/weather/${wid}.htm”;
str=`iconv -f gbk -t utf8 /tmp/weather.html | grep ’show_weather’ | sed -e ’s/show_weather(”//g’|sed -e ’s/),\ “hd\.htm.*//g’ | sed -e ’s/new Array(//g’ | sed -e “s/[\"|\ ]//g” | sed -e “s/,’/ /g” |sed -e “s/’//g”|sed -e “s/index.htm#$wid//g”|sed -e “s/),);//g”`;
#echo “str=${str}”;
AnArray=( ${str} );
time=`date +%k`;
#echo “time=$time”
echo “**********************************************************”
#if [ ${time} -gt 18 ] ; then
echo ${AnArray[0]}:
echo “今天天气:”
echo 温度:${AnArray[1]} 上午:${AnArray[2]} 下午:${AnArray[3]} 今晚:${AnArray[4]}
#echo 明天:${AnArray[6]}
echo “明天天气:”
echo 温度:${AnArray[5]} 上午:${AnArray[6]} 下午:${AnArray[7]} 明晚:${AnArray[8]}
#elif [ ${time} -gt 12 ] ; then
#echo ${AnArray[0]}: ${AnArray[1]} 下午:${AnArray[3]};晚上:${AnArray[4]}
#else
#echo ${AnArray[0]}: ${AnArray[1]} 上午:${AnArray[2]};下午:${AnArray[3]}
#fi
echo “**********************************************************”
rm -f /tmp/weather.html;
exit 0;

远行结果:

pjq@pjq-desktop:~/myshell$ ./weather
please keyin the city code
city:上海
**********************************************************
上海:
今天天气:
温度:3℃~16℃ 上午:晴 下午:晴转多云 今晚:多云
明天天气:
温度:6℃~14℃ 上午:晴转多云 下午:晴 明晚:晴
**********************************************************


说明:最近看了一本名为《鸟哥的私房菜》的书,所以想学脚本

星期六, 01月 5th, 2008

那本书写得通俗易懂,比较适合菜鸟们自学。

鸟哥V-bird说,要想学好LINUX一定要懂得命令,懂得写脚本。书里还有关于X-WINDOW很耗资源的说法,可以推想他写这本书的时候,电脑硬件比较贵,并且速度很受限制,但现在时代不同了,随便买一个电脑开个compiz都不成问题。 所以建议V哥可以对这段内容适当改改了:)

LINUX命令确实很有魅力,能够使你为之痴迷并直至疯狂的地步!~~!

现在水平还比较菜,将我用到的一些命令列出来下:

ls -ali

mkdir

fdisk

du -sh /* 比较有用,用来统计某个目录下每个文件或文件夹的大小

ping

netstat -an

ps -aux

glxgears 没事跑跑显卡,希望奇迹能够出现

vim 很好,很强大的纯文本编辑器

grep -n (显示行数) -v(不包括keywords)

cat

sort -g(用数字排序) -r(反向)

cp

ln -s(软链接)

mv (移动或改名)

cut -d “:” -f1

bc 文本计算器,可以用scale=n设置有效位数

为了缓解学习压力,充分利用free time,开始学习各种命令,并尝试写一些很小的脚本

星期六, 01月 5th, 2008

1.一个很无聊的脚本,其实只能算一个小命令

用来将arp文件中的IP解析出来,并排序显示出来

#!/bin/sh
#this shell is used to show the arp infomation,and sort the IP
echo “show the arp infomation,IP from 1–255″
echo “*****************”
cat /proc/net/arp | grep -v IP |cut -d ” ” -f1 | cut -d “.” -f4| sort -g
echo “*****************”

2.无聊透顶!!~其实ping就已经可以实现了,呵呵,只是将那一大串信息简缩为一个“OK”

第一次写脚本,主要是实践,学习if ;then … fi的用法

#!/bin/sh
#this shell is used to detect the network is Ok
#and print some useful info.
#ping 10.0.1.1 -c 4 >result.txt
echo -n “please keyin the host:”
read host
#host=$1
result=` ping $host -c 4 | grep transmitted | cut -d “,” -f3 `
echo “result=$result”
#if “$result”=” 0% packet loss” ; then
if [ "$result" = " 0% packet loss" ] ; then
echo “the host:$host is OK”
else echo “the host:$host is error”
fi

Recent Posts:
  1. 博客搬迁了~
  2. Android live cd试用及介绍
  3. Android Browser Introduction 2:结构图
  4. Android Browser Introduction 1
  5. 从20080707--20090707
  6. Rate My Life Quiz!
  7. Registration
  8. 在公司电脑装上了linux,还存在诸多问题
  9. NND,苏州电信想钱想疯了,上网1.2元/时,强推天冀!!!
  10. google.com被及艾服达不溜了

Register Login