linux中常用技巧总结
2010年09月02日 星期四 上午 01:11
|
至于这一篇blog我当然回经常更新的,不然学的这些零碎的东西很快就忘记了。。
1,mysql备份:
mysqldump -uuser -ppassword
如果不写table,默认把整个database备份下来。
2,makefile 中用tab键,不能用空格。也不要从剪贴版乱copy。
find * -type f 会把路径都显示出来。查找文件比ls -R方便。
例如:
[yangbin1@vHost-RH9 my]$ find * -type f | grep mysql.c
linuxc/mysql_connect linuxc/mysql_connect.c linuxc/mysql.c sql/mysql.c
在当前目录以及子目录中文件中查找sendfile()函数。
grep -Ra "sendfile" *
只在当前目录中查找
grep "sendfile" *
3,主机时间每天晚上同步一次,把下面的命令加入contab中:
#for standard time
30 0 * * * /usr/sbin/ntpdate tick.ucla.edu tock.gpsclock.com ntp.nasa.gov timekeeper.isi.edu usno.pa-x.dec.com > /dev/null
4,得到昨天的时间(bsd中) date -v -1d
5,取得现在的时间unix c
#include<time.h>
#include<stdio.h> #include<strings.h>
main()
{
}
计算时间差
difftime(time_t time1, time_t time0) / 86400
好象最大到2035年,不太清楚。
6,利用现存两个文件,生成一个新的文件
删除交集,不同的部分放到一个新文件中。
cat list.txt list.txt.old | sort | uniq -u > list.txt.new
取出两个文件的并集,重复的行只保留一份.
cat file1 file2 | sort | uniq > file3
取出两个文件的交集,只留下同时存在于两个文件中的文件.
cat file1 file2 | sort | uniq -d >file3
7,一个进程的多个线程中不但共享文件描述符,还共享文件指针的位置。所以被别的线程读过的文件,不要忘记lseek到文件开始处。
8,sendfile()在freebsd和linux上的区别除了参数个数不一样外,前两个参数的顺序也不一样。
#ifndef FREEBSD
//..... linux sendfile if(-1 ==sendfile(fd,fds[i].fd,0,fds[i].size)) #else //......freebsd sendfile if (-1 ==sendfile(fds[i].fd,fd,0,0,NULL,NULL,0)) #endif
perror(sendfile error!);
9,如何检测另一个进程是不是死掉了。
ret=kill(pid,0);
0 means no signal sent,but error checking is still performed; ret==0 means process running; ret==-1 and errno=ESRCH means process doesn't exist. other errors check urself
另一个进程启动时候将进程号写到一个文件里。
这个程序来读。然后kill检测它是不是有效的进程。
如果ret不为零,说明进程死掉了,你可以用配合system()将它重新启动。
10, 让一个进程在终端退出后,仍然在后台运行。
nohup ./receivefile
11, 查看系统信息
最大可以打开文件的数目,cpu和内存信息
cat /proc/sys/fs/file-max
cat /proc/cpuinfo
cat /proc/meminfo
linux上查看发行版本
cat /etc/issue
查看系统相关信息
uname -a
在c中查看当前系统是什么os
int uname(struct utsname *buf)
12,修改了/etc/ld.so.conf后,ldconfig -v 使设置生效。
ldd
13,在mysql中创建一个mydb库。将权限给某个user,密码为user123。
create database mydb;
grant all privileges on mydb.* to user@localhost identified by 'user123';
14,查看某主机上的web服务。
telnet 10.210.128.189 80
GET /index.html HTTP/1.0 HOST:yangjian.sina.com.cn
15,将字符串格式化成一定的数据。
sscanf(fielName, "%[ a-z]%[0-9].%[a-z]", user, date, suffix); |

287

被折叠的 条评论
为什么被折叠?



