Linux系统下的常用工具
Linux系统下的常用指令
更改用户权限和组权限(这一操作得在root用户下进行)
# chown -R xxxxx:xxxxx 文件名
其中xxxxx为所需要更改的用户名。假如我现在有个用户叫haha,有一个权限为root的hello.c的文件,我需要将hello.c的文件的权限更改为haha用户权限,那么应该写如下指令:
# chown -R haha:haha hello.c
迭代的删除文件
$ rm -r 文件夹名
比如说现在有一个叫test的文件夹,test文件夹目录下还有其他的文件夹或者文件,那么我想要将test以及其文件夹下面的所有文件一并删除就可以采用上面的命令行实现。具体指令如下:
$ rm -r test
代码的编译与运行(利用gcc)
$ gcc xxx.c -o xxx
$ ./xxx
查看当前目录的完整路径
$ pwd
Linux系统下的常用工具
Makefile
以下内容摘自《基于项目驱动的嵌入式Linux应用设计开发》
下面通过实例来介绍以下Makefile文件的编写规则。假如我们现在有三个c语言程序main.c、t1.c、t2.c和三个头文件d1.h、d2.h、d3.h,且三个头文件均为空。
main.c的内容如下:
//main.c
#include<stdio.h>
#include"d1.h"
extern void s1();
extern void s2();
int main(void){
printf("This is main.\n");
s1();
s2();
return 0;
}
t1.c的内容:
//t1.c
#include<stdio.h>
#include"d1.h"
#include"d2.h"
void s1(void){
printf("This is s1.\n");
}
t2.c的内容
//t2.c
#include<stdio.h>
#include"d2.h"
#include"d3.h"
void s2(void){
printf("This is s2.\n");
}
编写Makefile文件,其内容为:
//Makefile
main:main.o t1.o t2.o
gcc -o main main.o t1.o t2.o
main.o:main.c d1.h
gcc -c main.c
t1.o:t1.c d1.h d2.h
gcc -c t1.c
t2.o:t2.c d2.h d3.h
gcc -c t2.c
.PHONY:clean
clean:
rm -f main main.o t1.o t2.o
上面代码含义解释如下图所示:
执行make命令并运行程序具体如下:
在默认情况下,make只更新Makefile中的第一个目标,如果希望更新更多个目标文件,可以使用一个特殊的目标all,假如想在一个Makefile中更新main和test这两个程序文件,可以假如下面的语句:
all:main test
Makefile在驱动模块中的使用
Makefile文件编写如下:
obj-m:=hello.o
KERNELDIR:=/urs/src/kernels/2.6.32-642.el6.x86_64
modules:
make -C KERNELDIR M='pwd' modules
报错如下:
make -C KERNELDIR M='pwd' modules
make: *** KERNELDIR: No such fileaa or directory. Stop.
make: *** [modules] Error 2
待解决。。。