LINUX/UNIX 命令
LINUX 和 UNIX 命令一样吗? 我现在是学LINUX ,不知道UNIX下那些命令是不是适用? 可以举例子最好
更新时间:2023-05-19 15:05
最满意答案
下面是读取一个文件 并复制成新文件 #include#include #include #include #define BUFFER_SIZE 1024 int main(int argc, char **argv) { FILE *from_fd; FILE *to_fd; long file_len = 0; char buffer[BUFFER_SIZE]; char *ptr; //判断传入参数 if(argc != 3) { printf("Usage: %s fromfile tofile", argv[0]); exit(1); //异常退出返回1 } //打开原文件 if((from_fd = fopen(argv[1], "rb")) == NULL) { printf("Read %s Error\n", argv[1]); exit(1); } //创建目的文件 if((to_fd = fopen(argv[2], "wb")) == NULL) { printf("Write %s Error\n", argv[2]); exit(1); } //侧得文件大小 fseek(from_fd, 0L, SEEK_END); file_len = ftell(from_fd); fseek(from_fd, 0L, SEEK_SET); printf("from file size is = %ld\n", file_len); //进行文件拷贝 while(!feof(from_fd)) { fread(buffer, BUFFER_SIZE, 1, from_fd); //fread 为c标准 库里函数 // read 为Linux系统调用, 返回成功读取了多少字节 出错则返回-1 if(BUFFER_SIZE >= file_len) { fwrite(buffer, file_len, 1, to_fd); } else { fwrite(buffer, BUFFER_SIZE, 1, to_fd); file_len = file_len - BUFFER_SIZE; printf("copy success!\n"); } bzero(buffer, BUFFER_SIZE); } fclose(from_fd); fclose(to_fd); exit(0); //返回0 表示成功 }
其他回答
<?php $maximum_filesize = 1024 * 200; // 200kb //设定最大上传大小 200kb $maximum_file_count = 10; // keep maximum 10 files on server //最多个数 $upload_tree_param = 'gettree'; //以下几个是“猜测”的,毕竟我也不知道源码的目录结构哈,见谅 //tree参数 $upload_file_param = 'filename'; //file $upload_path_param = 'filepath'; //path $upload_directory = 'images/'; //应是图片存储路径(相对的) $remove_path_param = 'removepath'; //remove_path $domain=''.$_server['http_host']; //网站域名(一般表示类似与***.com这个东西) if(isset($_files[$upload_file_param])){ //如果$upload_file_param被设定了---前面设定了的 if($_files[$upload_file_param]['size'] <= $maximum_filesize){ //如果客户端上传的图片大小小于或等于maximum_filesize(限定尺寸) $path = $_get[$upload_path_param]; //$path为从客户端获取的$upload_path_param变量的值 $path = preg_replace("#^$upload_directory#", '', $path); //对$path处理使之匹配 "#^$upload_directory#"---- 具体是什么,我也不是 //很清楚 哈,我对正则不是很了解 $path = $upload_directory.$path; //让$path的值为"完整"的如:"images/ttt.jpg" move_uploaded_file($_files[$upload_file_param]['tmp_name'], $path.$_files[$upload_file_param]['name']); //上传。通过函数move_uploaded_file函数上传, //其中$_files[$upload_file_param]['tmp_name']为,你上传客户端的那个 //text文本框里的东西 //$path.$_files[$upload_file_param]['name']),这个是你上传后名字 //应该哪里有个路径,估计是我没看到。呵呵 } }elseif(isset($_get[$upload_tree_param])){ //如果$_get[$upload_tree_param存在----应该是后台设定的目录存储树了吧 $xml = '<?'.'xml version="1.0" encoding="utf-8"'.'?>'; $xml .=getfilexmltree($upload_directory); echo $xml; //上面三个表示输出xml文件头 }elseif(isset($_get[$remove_path_param])){ //继续判断$_get[$remove_path_param它的存在 $path = $_get[$remove_path_param]; //上面写过这东西,就不写了 $path = preg_replace("#^$upload_directory#", '', $path); $path = $upload_directory.$path; logdata('remove '.$path); //哦,不清楚这个不好意思 removefile($path); }else echo file_get_contents('flexrtf.html'); function removefile($path){ if(is_dir($path)){ //如果存在$path这个目录 $dir = opendir($path); //则打开,句柄指向$dir while($file = readdir($dir)){ //如果$file---表示读取$dir正确 //则 if($file=='.'||$file=='..')continue; //上面表示在$file中只有".",或".." //也就是,不会让目录转换出错,---下面那个就是去掉斜杠 if(is_dir($path.$file))removefile($path.$file.'/'); else @unlink($path.$file); // } closedir($dir); //关闭 下面差不多都是和上面有类似的了。不写了,好累哦。。。 @rmdir($path); }else @unlink($path); } function getfilexmltree($path){ global $domain; $label = split('/', preg_replace('/\/+$/','',$path)); $label = $label[sizeof($label)-1]; $xmldirs = ''; $xmlfiles = ''; $dir = opendir($path); while($file = readdir($dir)){ if($file=='.'||$file=='..')continue; if(is_dir($path.$file))$xmldirs.=getfilexmltree($path.$file.'/'); else $xmlfiles.='<node label="'.$file.'" path="'.($path).'" url="'.$domain.'/flexrtf/'.($path.$file).'" size="'.filesize($path.$file).'"/>'; } closedir($dir); return '<node label="'.$label.'" path="'.$path.'" isbranch="true">'.$xmldirs.$xmlfiles.'</node>'; } function logdata($msg){ $fp = fopen('./data.txt', 'a'); fwrite($fp, $msg."\n"); fclose($fp); }
相关问答
更多-
linux操作系统下,加上行号输出一个文本文件,列出所有这样的方法[2023-10-31]
nl命令在linux系统中用来计算文件中行号。nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等等的功能。 1.命令格式: nl [选项]... [文件]... 2.命令参数: -b :指定行号指定的方式,主要有两种: -b a:表示不论是否为空行,也同样列出行号(类似 cat -n); -b t:如果有空行,空的那一行不要列出行号(默认值); -n :列出行号表示的方法,主要有三种: -n ln:行号在 ... -
能够查看文本文件的linux命令[2022-02-05]
cat -
linux命令,清除一个文本文件的命令?[2023-09-26]
#rm filename.txt;touch filename.txt --------------- 一个命令?再想一想 -
linux怎么直接打开文本文件[2023-04-10]
通过命令+文件名查看内容。如下命令可以查看。 1, cat :由第一行开始显示文件内容; 2,tac:从最后一行开始显示,可以看出tac与cat字母顺序相反; 3,nl:显示的时候输出行号; 4,more:一页一页的显示文件内容; 5,less与more类似,但它可以向前翻页; 6,head:只看前几行; 7,tail:只看最后几行; 8,od:以二进制的方式读取文件。 9,vi和vim作为编辑器,也可以打开文件查看内容。 -
c语言如何读写 linux文本文件[2023-03-29]
Linux下C语言的文件(fputc,fgetc,fwrite,fread对文件读写操作) // fputc 向文件写入字符 #include #include main() { FILE *fp; char ch; if((fp=fopen("test.txt","w"))==NULL) { printf("不能打开文件\n"); exit(0); } while ((ch=getchar())!='\n') fputc( ch, fp ); fclose( ... -
linux 怎么读[2022-01-18]
lin nin ke si 林您克斯 lin 重读 -
linux下QT写文本文件[2022-06-29]
QT 我不懂,但 C 是可以的,参考程序: #include #include int main() { FILE *myfile = fopen("test.txt", "w"); char msg[] = " 为中华之崛起而读书"; fwrite(msg, strlen(msg), 1, myfile); fclose(myfile); return 0; } -
linux命令,清除一个文本文件的命令?[2022-03-07]
rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除。对于链接文件,只是删除了链接,原有文件均保持不变。 rm是一个危险的命令,使用的时候要特别当心,尤其对于新手,否则整个系统就会毁在这个命令(比如在/(根目录)下执行rm * -rf)。所以,我们在执行rm之前最好先确认一下在哪个目录,到底要删除什么东西,操作时保持高度清醒的头脑。 1.命令格式: rm [选项] 文件… 2.命令功能: 删除一个目录中的一个或多个文件或目录,如果没有使用- ... -
linux 下如何读一个文本文件?要求有代码和注释[2023-03-25]
下面是读取一个文件 并复制成新文件 #include #include #include #include #define BUFFER_SIZE 1024 int main(int argc, char **argv) { FILE *from_fd; FILE *to_fd; long file_len = 0; char buffer[BUFFER_SIZE]; char *ptr; //判断传入参数 if(argc != 3) { printf("Usage: %s fromfile tofile" ... -
wc -l <
为我显示行 数字1 - 7的示例文件 输出: scottsmudger@ns207588:~ $wc -l < test 7 从手册页: -l, --lines print the newline counts wc -l < displays lines for me example file with numbers 1 - 7 outputs: scottsmudger@ns207588:~ $wc -l < test 7 Fro ...