gedit linux下的纯文本编辑器
lseek
tar
fcntl
shutdown及其他关机
init
dd
aptitude及其他安装
查找命令which、whereis、locate、find
grep
man手册
当我们写应用程序时,很多API原型都不可能记得,所以要实时查询,用man手册
man 1 xx查linux shell命令(可执行程序)
man 2 xxx查linux系统API
man 3 xxx查C库函数
包含必要的系统头文件
man 2 open
man 2 close
man 2 read
man 2 write
lseek
首先看下函数: off_t lseek(int fd, off_t offset, int whence);
所需要头文件:
#include <sys/types.h>
#include <unistd.h>
参数:
fd 表示要操作的文件描述符
offset是相对于whence(基准)的偏移量
whence 可以是SEEK_SET(文件指针开始),SEEK_CUR(文件指针当前位置) ,SEEK_END为文件指针尾
返回值:文件读写指针距文件开头的字节大小,出错,返回-1
lseek 主要作用是移动文件读写指针,因此还有以下两个作用
1.拓展文件,不过一定要一次写的操作。迅雷等下载工具在下载文件时候先扩展一个空间,然后再下载的。
https://blog.youkuaiyun.com/clamercoder/article/details/38361815空洞文件
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
void main()
{
int add_len = 1024*8;
int fd=open("test.txt",O_RDWR);
if(fd == -1)
{
perror("open test.txt");
exit(-1);
}
lseek(fd,add_len-1,SEEK_END);
write(fd,"0",1);
//程序在执行 lseek() 后,系统文件指针将转移到 结束位置,但是还没有向文件中的输出数据,在执行 write() 后,将向文件中输出一个字节的 '\0' 标志,这是典型的先分配后输出文件数据的使用方法。
以后程序的对文件的操作将调用 lseek() 函数转移到对应的结构体位置,输出对应的数据。
}
2.获取文件大小
//获取文件大小
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
void main()
{
int fd=open("test.txt",O_RDWR);
if(fd == -1)
{
perror("open test.txt");
exit(-1);
}
printf("file len:%d \n",lseek(fd,0,SEEK_END));
close(fd);
}
tar
https://www.cnblogs.com/wuyuetan/p/3778165.html
-c :建立一个压缩文件的参数指令(create 的意思);
-x :解开一个压缩文件的参数指令!
-t :查看 tarfile 里面的文件!
//特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!
//因为不可能同时压缩与解压缩。
-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?