find grep等一些命令必须熟悉,环境变量的设置,读取等。
一些shell脚本程序要能够看懂。
查看版本信息:
uname -a //查看内核版本号及系统名称
cat /proc/version //同上
文件系统和linux内核版本有关系吗?
有五个方面的联系:
1、就是3楼说的的编译器的问题:需要用相同的编译器。
2、kernel中必须配置对根文件系统类型的支持:你的kernel中必须支持yaffs
3、kernel中对flash的分区,必须和实际情况一致。
4、bootloader传给kernel的参数必须要和实际情况一致
5、bootloader中定义的机器ID必须和kernel中定义的一致
1. 先找 /sbin 下是否有init服务
2. /etc/init
3. /bin/init
4. 如果都找不到,就执行 /bin/sh
这个过程中,只要某一个步骤找到init服务,linux核心就会去执行该目录中的init。
如果到最后核心还是找不到init服务,linux核心会显示“kernel panic - not syncing : Attempted to kill init ! ”的错误信息,然后终止启动工作,linux核心再悄悄的死去。
wc命令:
通常利用Linux的wc命令和其他命令结合来计算行和其他信息。
在Linux下用wc进行计数。返回文件的行数、字数、字节数等。
看个例子:
wc wc1.txt
3 5 16 wc1.txt
输出信息依次是:行数 字数 字节数 文件名称。再具体点,单个统计。
wc -m filename:显示一个文件的字符数
wc -l filename:显示一个文件的行数
wc -L filename:显示一个文件中的最长行的长度
wc -w filename:显示一个文件的字数
读源码步骤:readme-kconfig-makefile-初始化函数(如subsys_initcall或module_init)-...
__init标记的定义:#define __init __attribute__ ((__section__ (".init.text")))
#define subsys_initcall(fn) __define_initcall("4",fn,4)
察看日志文件:tail -f /var/log/messages
lsmod命令用来列出当 前系统加载的模块,可以当作硬件模块浏览器。
diff命令的使用:
例如: diff /usr/xu mine
把目录/usr/xu 中名为mine的文件与当前目录中的mine文件进行比较。
通常输出由下述形式的行组成:
n1 a n3,n4
n1,n2 d n3
n1,n2 c n3,n4 这些行类似ed命令把filel转换成file2。字母(a、d和c)之前的行号(n1,n2)是针对file1的,其后面的行号(n3,n4)是针对file2的。字母a、d和c分别表示附加、删除和修改操作。
在上述形式的每一行的后面跟随受到影响的若干行,以”<”打头的行属于第一个文件,以”>”打头的行属于第二个文件。
diff能区别块和字符设备文件以及FIFO(管道文件),不会把它们与普通文件进行比较。
如果file1和file2都是目录,则diff会产生很多信息。
5>diff最常用的功能
diff有很多功能平时我们不常用到,最常用的功能莫过于生成patch文件了:
diff -urN old/ new/ > mysoft.patch
参数 -u 表示使用 unified 格式,-r 表示比较目录,-N 表示将不存在的文件当作空文件处理,这样新添加的文件也会出现在patch文件中。
然后在需要应用patch的地方使用下述命令即可:
patch -p0 < mysoft.patch
mkdir -p parents的意思,创建所有遗失的父目录parents的意思。
trap命令用于捕获指定的信号并执行预定义的命令。
ipaddr=`/sbin/ifconfig | grep 'inet addr:' | grep -v '127.0.0.1'| tee temp.txt | cut -d : -f3 | awk '{print $1}'`echo $ipaddr
find . -name '*.[ch]' -print | xargs grep "mtj" | more
find . -name '*.[ch]' -type f -print
find . -name '*.[ch] -exec chmod 444 {} \
grep -n "the" *.txt 行号
grep -l "the" *.txt 只显示文件名
-w限定为完整单词
把错误和输出重定向到同一文件:
prog 1>out 2>&1
简单脚本:
#!/bin/bash
a=1
b=2
if [[ $a -eq $b ]]//比较字符串使用==
then
echo "equal"
else
echo "unequal"
fi
//文件测试:
if [ ! -d $file1 ]
then
echo "File is not a directory"
fi
[ -r myfile.txt] && echo "the file is readable."
case语句:
#!/bin/bash
var=2
case "$var" in
[0-5] ) echo "The value is between 0 and 5";;
[6-9] ) echo "";;
*) echo ""
esac
exit
while循环:
#!/bin/bash
outer=0
while [ "$outer" -lt 5 ] ; do
inner=0
while [ $inner -lt 3 ] ; do
echo $outer * $inner = $(($outer * $inner))
inner=$(expr $inner + 1)
done
let outer=$outer+1
done
exit
for循环:
#!/bin/bash
#save the current directory
curwd=$PWD
#change the current directory to /home
cd /home
echo -n "users on the system are:"
#loop through each file (via the wildcard)
for user in *; do
echo -n " $user"
done
echo
#return to the previous directory
cd $curwd
exit
read命令接受用户输入存入变量:
read var
test string
echo $var
函数:
#!/bin/bash
function sum ()
{
if [ $# -ne 2 ] ; then //表示传入函数的变量个数
echo "usage is sum <param1> <param2>"
exit
fi
return $(( $1 + $2 )) //函数的返回值,可以使用$?查看
}
sum 5 10 //调用
ret= $?
echo $ret