linux下编译多个文件
例如:
/home/files文件夹下有文件main.c:
#include <stdio.h>
#include "tou.h"
void main()
{
a();
}
/home/files/common文件夹下有文件tou.h和shixian.c。
tou.h为:
extern void a();
若有多个shixian文件,比如shixian1.c, shixian2.c,都可以在tou.h中用extern声明出来。
shixian.c为:
#include <stdio.h>
void a()
{
printf("a");
}
编译时用命令:gcc main.c ./common/shixian.c -o main -I /home/files/common
其中,-I /home/files/common代表链接到头文件所在目录。若.h文件都在本目录下,则不用加-I指明.h文件所在文件夹。
另外,-lm表示链接到数学函数库。
相关文档:
ls -l|grep ^d ----列出当前目录下的文件夹
ls -l|grep ^d|grep "tmp" ----列出当前目录下明子含有"tmp"的文件夹
for dir in `ls -l ~/dxy/|grep ^d | awk '{print $9}'` ---- awk '{print $9}' ,只print 文件夹的名字
do
echo "==== $dir"
cd ~/dxy;cd ......
1. Linux 脚本编写基础
1.1 语法基本介绍
1.1.1 开头
程序必须以下面的行开始(必须放在文件的第一行):
#!/bin/sh
符号#!用来告诉系统它后面的参数是用来执行该文件的程序。在这个例子中我们使用/bin/sh来执行程序。
当编辑好脚本时,如果要执行该脚本,还必须使其可执行。
要使脚本可执行:
编译 ch ......
文件fun.c,fun.h,hello.c,hello.h,main.c动态库函数都在fun.c和hello.c里面
----------------------------
fun.c:
int add(int a, int b)
{
return a+b;
}
fun.h:
#ifndef _FUN_H_11
#define _FUN_H_11
int add(int a, int b);
#endif
----------------------------
hello.c:
#i nclude <stdio ......
在我们通过SSH登陆服务器后,一般来说,所做的操作或者命令的输入都是属sshd下的shell的子进程,例如打开个SSH终端,输入ping www.163.com >>output.txt &,然后查看进程情况:
$ ps -ef|grep ping
sszheng 27491 27467 0 10:20 pts/0 00:00:00 ping www.163.com
sszheng 27535 27467 ......