make
官方文档
https://www.gnu.org/software/make/manual
跟我一起写 Makefile
https://blog.csdn.net/haoel/article/details/2886
https://blog.csdn.net/haoel/article/details/2899
GNUmakefile > makefile > Makefile
https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html
=和:=的区别
https://blog.csdn.net/b876144622/article/details/80372161
%和*的区别
https://www.cnblogs.com/warren-wong/p/3979270.html
@
echo “hello”:显示命令和结果
@echo “hello”:只显示结果
origin、wildcard、patsubst
https://www.zhaixue.cc/makefile/makefile-origin-function.html
https://www.zhaixue.cc/makefile/makefile-function.html
https://www.zhaixue.cc/makefile/makefile-text-func.html
.SECONDEXPANSION
https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
targets : normal-prerequisites | order-only-prerequisites
https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html
隐含规则
https://blog.csdn.net/haoel/article/details/2897
模式规则、后缀规则
https://blog.csdn.net/haoel/article/details/2898
%.d: %.c
https://www.gnu.org/software/make/manual/html_node/Automatic-Prerequisites.html
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
以hello.c为例,上面的sed语句等价于
sed 's,hello.o: ,hello.o hello.d : ,g' < hello.d.$$$$ > hello.d;
gcc
hello.c
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
预处理器(preprocessor,cpp)
cpp hello.c -o hello.i
gcc -E hello.c -o hello.i
编译器(compiler,cc1)
sudo find / -name cc1
/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1
/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1 hello.i -o hello.s
gcc -S hello.c/i -o hello.s
汇编器(assembler,as)
as hello.s -o hello.o
gcc -c hello.c/i/s -o hello.o
链接器(linker,ld)
gcc hello.o -o hello -v
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. hello.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
collect2:https://gcc.gnu.org/onlinedocs/gccint/Collect2.html
ld hello.o /usr/lib64/crt1.o /usr/lib64/crti.o /usr/lib64/crtn.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o -dynamic-linker /lib64/ld-linux-x86-64.so.2 -lc -o hello
gcc hello.c/i/s/o -o hello
-I(大写i):指定头文件目录
-L:指定库文件目录
-l(小写l):指定静/动态库
ip route add
ip route add 10.0.0.0/24 dev eth0
通过dev eth0添加的路由的gateway为0.0.0.0(二层路由),给网卡配置ip会生成一条该路由
ip route add 10.0.0.0/24 gw 192.168.0.1
通过gw 192.168.0.1添加的路由的gateway为192.168.0.1(三层路由),gw必须和某一个本机ip同网段
ping -s
-s表示icmp payload长度(不包含20B ip头和8B icmp头)
最小长度:0
MTU最小长度:46 - 28 = 18
MTU最大长度:1500 - 28 = 1472
最大长度:65535 - 28 = 65507
在用ping做链路探测时,注意-s的取值范围最好为18-1472,防止被某些防火墙丢包
[root@localhost ~]# ping 223.5.5.5 -c 1 -s 0
[root@localhost ~]# ping 223.5.5.5 -c 1 -s 18
[root@localhost ~]# ping 223.5.5.5 -c 1 -s 1472
[root@localhost ~]# ping 223.5.5.5 -c 1 -s 1473
[root@localhost ~]# tcpdump -nnvvi any icmp and dst host 223.5.5.5
11:32:49.900129 IP (tos 0x0, ttl 64, id 3732, offset 0, flags [DF], proto ICMP (1), length 28) # IP长度
192.168.11.105 > 223.5.5.5: ICMP echo request, id 27311, seq 1, length 8 # ICMP长度
11:32:59.386886 IP (tos 0x0, ttl 64, id 10410, offset 0, flags [DF], proto ICMP (1), length 46)
192.168.11.105 > 223.5.5.5: ICMP echo request, id 27917, seq 1, length 26
11:33:11.666522 IP (tos 0x0, ttl 64, id 22678, offset 0, flags [DF], proto ICMP (1), length 1500)
192.168.11.105 > 223.5.5.5: ICMP echo request, id 28665, seq 1, length 1480
11:33:25.003144 IP (tos 0x0, ttl 64, id 24726, offset 0, flags [+], proto ICMP (1), length 1500)
192.168.11.105 > 223.5.5.5: ICMP echo request, id 29355, seq 1, length 1480
11:33:25.003155 IP (tos 0x0, ttl 64, id 24726, offset 1480, flags [none], proto ICMP (1), length 21)
192.168.11.105 > 223.5.5.5: ip-proto-1
crontab
配置文件:
/etc/crontab
/etc/cron.d/
/var/spool/cron/{user}(crontab -e)
cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
在/etc/cron.d/目录下有0hourly文件,cat /etc/cron.d/0hourly
# Run the hourly jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
01 * * * * root run-parts /etc/cron.hourly
在/etc/cron.hourly/目录下有0anacron文件,cat /etc/cron.hourly/0anacron
#!/bin/sh
# Check whether 0anacron was run today already
if test -r /var/spool/anacron/cron.daily; then
day=`cat /var/spool/anacron/cron.daily`
fi
if [ `date +%Y%m%d` = "$day" ]; then
exit 0;
fi
# Do not run jobs when on battery power
if test -x /usr/bin/on_ac_power; then
/usr/bin/on_ac_power >/dev/null 2>&1
if test $? -eq 1; then
exit 0
fi
fi
/usr/sbin/anacron -s
cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
在/etc/cron.daily目录下有logrotate文件,cat /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
/etc/cron.weekly/和/etc/cron.monthly/是空目录
logrotate
配置文件:
/etc/logrotate.conf
/etc/logrotate.d/
cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
# system-specific logs may be also be configured here.
在/etc/logrotate.conf中include /etc/logrotate.d,cat /etc/logrotate.d/syslog-ng
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron /var/log/kern{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslog-ng.pid 2> /dev/null` 2> /dev/null || true
endscript
}
使用logrotate的步骤:
1、配置文件:在/etc/logrotate.d/目录下创建配置文件
2、定时任务:可以使用已有的每天定时任务,也可以使用自定义定时任务