http://code.google.com/edu 可获得华盛顿大学编写的所有课程资料,以及其他用于帮助学习这一前沿技术的工具和资源。
如果想了解此类项目的意义,请观看系列讲座视频(共五部分,原是谷歌工程部实习生的学习资料),其中介绍了大规模集群计算的一些基本概念。
10/15/2007
10/09/2007
cut、tr 等命令格式化字符串
CurreIP=$(wget http://freedns.afraid.org/dynamic/check.php -o /dev/null -O /dev/stdout | grep Detected | cut -d : -f 2 | cut -d '<' -f 1 | tr -d " ")
cat check.php :
Detected IP : 210.73.65.34, 210.73.65.77
HTTP_CLIENT_IP :
HTTP_X_FORWARDED_FOR : 210.73.65.34, 210.73.65.77
REMOTE_ADDR : 72.20.25.132
cat check.php :
Detected IP : 210.73.65.34, 210.73.65.77
HTTP_CLIENT_IP :
HTTP_X_FORWARDED_FOR : 210.73.65.34, 210.73.65.77
REMOTE_ADDR : 72.20.25.132
9/18/2007
vim + cscope/ctags
生成符号索引文件: cscope -Rbkq
这个命令会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。
上面所用到的命令参数,含义如下:
-R: 在生成索引文件时,搜索子目录树中的代码
-b: 只生成索引文件,不进入cscope的界面
-k: 在生成索引文件时,不搜索/usr/include目录
-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
按照cscope手册上提供的方法,先产生一个文件列表,然后让cscope为这个列表中的每个文件都生成索引。
为了方便使用,编写了下面的脚本来更新cscope和ctags的索引文件:
#!/bin/sh
find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files
cscope -bkq -i cscope.files
ctags -R
这个脚本,首先使用find命令,查找当前目录及子目录中所有后缀名为".h", ".c"和".cc"的文件,并把查找结果重定向到文件cscope.files中,然后cscope根据cscope.files中的所有文件,生成符号索引文件。最后一条命令使用ctags命令,生成一个tags文件。
cscope的主页在:http://cscope.sourceforge.net
vim的主页:http://www.vim.org
这个命令会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。
上面所用到的命令参数,含义如下:
-R: 在生成索引文件时,搜索子目录树中的代码
-b: 只生成索引文件,不进入cscope的界面
-k: 在生成索引文件时,不搜索/usr/include目录
-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
按照cscope手册上提供的方法,先产生一个文件列表,然后让cscope为这个列表中的每个文件都生成索引。
为了方便使用,编写了下面的脚本来更新cscope和ctags的索引文件:
#!/bin/sh
find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files
cscope -bkq -i cscope.files
ctags -R
这个脚本,首先使用find命令,查找当前目录及子目录中所有后缀名为".h", ".c"和".cc"的文件,并把查找结果重定向到文件cscope.files中,然后cscope根据cscope.files中的所有文件,生成符号索引文件。最后一条命令使用ctags命令,生成一个tags文件。
cscope的主页在:http://cscope.sourceforge.net
vim的主页:http://www.vim.org
9/12/2007
malloc(0) 的问题
char *p;
p = (char *)malloc(0);
以上代码没有错误,但 p 的分配的空间大小是多少呢,不确定?
至于为什么可以分配成功,看看 malloc 的说明就明白了:
malloc returns a void pointer to the allocated space,or null if there is insufficient memory available.
9/06/2007
查看pci设备的方法?!
大家都知道可以使用 lspci 查看pci设备信息。PCI设备是其特定的ID号来标示的,包含vendor id, device id, subsystem等,这个ID是由一个组织统管并给各大硬件厂商分配。一般来说,一个精确的ID就唯一得确定了一种PCI设置,因此通过读取此ID就可以得知此设备究竟是什么东西。Linux发行版中的lspci工具就是做这个的。但由于发行版发行时间问题,系统自带的ID-设备对硬数据库可能比较陈旧,导致识别不出新的设备来,这是就会出现unknown device,如同上面我们看到的结果。遇到此类情况,解决方法是使用新的IDs数据库。对于Linux,有一个项目是构建公开的ID数据库,在这里:http://pciids.sourceforge.net/,可以在此网站直接下载其数据库http://pciids.sourceforge.net/pci.ids到本地,然后使用命令lspci -i path-to-pci.ids 来指定使用下载到的ID数据库来鉴别设备。
8/27/2007
汇总统计
1.汇总
样本文件,这里暂时称为 file1,内容如下:
a
a
b
b
a
b
c
a
d
b
b
b
d
a
c
--------------------
执行以下命令:
cat file1 | sort // 按照字母顺序排序
cat file1 | sort | uniq // 按照字母顺序排序且去除重复项
cat file1 | sort | uniq -c // 按照字母顺序排序且去除重复项,在每行前列出重复项的个数
cat file1 | sort | uniq -c | sort -rn // 在每行前列出重复项的个数,按个数排序且去除重复项
2.单词统计
cat file3
cat file3 | sed -e "s/ /\n/g"
cat file3 | sed -e "s/ /\n/g" | sort
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn
取头尾
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | head
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | head -n5
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | tail
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | tail -n5
统计词(总数,不重复的个数)有好几种办法
cat file3 | sed -e "s/ /\n/g" | sort | uniq | wc -l
cat file3 | sed -e "s/ /\n/g" | wc -l
cat file3 | wc
cat file3 | wc | cut -d" " -f2
cat file3 | wc -w
cat file3 | sed -e "s/ /\n/g" | wc -l
样本文件,这里暂时称为 file1,内容如下:
a
a
b
b
a
b
c
a
d
b
b
b
d
a
c
--------------------
执行以下命令:
cat file1 | sort // 按照字母顺序排序
cat file1 | sort | uniq // 按照字母顺序排序且去除重复项
cat file1 | sort | uniq -c // 按照字母顺序排序且去除重复项,在每行前列出重复项的个数
cat file1 | sort | uniq -c | sort -rn // 在每行前列出重复项的个数,按个数排序且去除重复项
2.单词统计
cat file3
cat file3 | sed -e "s/ /\n/g"
cat file3 | sed -e "s/ /\n/g" | sort
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn
取头尾
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | head
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | head -n5
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | tail
cat file3 | sed -e "s/ /\n/g" | sort | uniq -c | sort -rn | tail -n5
统计词(总数,不重复的个数)有好几种办法
cat file3 | sed -e "s/ /\n/g" | sort | uniq | wc -l
cat file3 | sed -e "s/ /\n/g" | wc -l
cat file3 | wc
cat file3 | wc | cut -d" " -f2
cat file3 | wc -w
cat file3 | sed -e "s/ /\n/g" | wc -l
订阅:
博文 (Atom)

