首页 \ 问答 \ LINUX/UNIX 命令

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 &#36;maximum_filesize = 1024 * 200; // 200kb //设定最大上传大小 200kb &#36;maximum_file_count = 10; // keep maximum 10 files on server //最多个数 &#36;upload_tree_param = 'gettree'; //以下几个是“猜测”的,毕竟我也不知道源码的目录结构哈,见谅 //tree参数 &#36;upload_file_param = 'filename'; //file &#36;upload_path_param = 'filepath'; //path &#36;upload_directory = 'images/'; //应是图片存储路径(相对的) &#36;remove_path_param = 'removepath'; //remove_path &#36;domain=''.&#36;_server['http_host']; //网站域名(一般表示类似与***.com这个东西) if(isset(&#36;_files[&#36;upload_file_param])){ //如果&#36;upload_file_param被设定了---前面设定了的 if(&#36;_files[&#36;upload_file_param]['size'] <= &#36;maximum_filesize){ //如果客户端上传的图片大小小于或等于maximum_filesize(限定尺寸) &#36;path = &#36;_get[&#36;upload_path_param]; //&#36;path为从客户端获取的&#36;upload_path_param变量的值 &#36;path = preg_replace("#^&#36;upload_directory#", '', &#36;path); //对&#36;path处理使之匹配 "#^&#36;upload_directory#"---- 具体是什么,我也不是 //很清楚 哈,我对正则不是很了解 &#36;path = &#36;upload_directory.&#36;path; //让&#36;path的值为"完整"的如:"images/ttt.jpg" move_uploaded_file(&#36;_files[&#36;upload_file_param]['tmp_name'], &#36;path.&#36;_files[&#36;upload_file_param]['name']); //上传。通过函数move_uploaded_file函数上传, //其中&#36;_files[&#36;upload_file_param]['tmp_name']为,你上传客户端的那个 //text文本框里的东西 //&#36;path.&#36;_files[&#36;upload_file_param]['name']),这个是你上传后名字 //应该哪里有个路径,估计是我没看到。呵呵 } }elseif(isset(&#36;_get[&#36;upload_tree_param])){ //如果&#36;_get[&#36;upload_tree_param存在----应该是后台设定的目录存储树了吧 &#36;xml = '<?'.'xml version="1.0" encoding="utf-8"'.'?>'; &#36;xml .=getfilexmltree(&#36;upload_directory); echo &#36;xml; //上面三个表示输出xml文件头 }elseif(isset(&#36;_get[&#36;remove_path_param])){ //继续判断&#36;_get[&#36;remove_path_param它的存在 &#36;path = &#36;_get[&#36;remove_path_param]; //上面写过这东西,就不写了 &#36;path = preg_replace("#^&#36;upload_directory#", '', &#36;path); &#36;path = &#36;upload_directory.&#36;path; logdata('remove '.&#36;path); //哦,不清楚这个不好意思 removefile(&#36;path); }else echo file_get_contents('flexrtf.html'); function removefile(&#36;path){ if(is_dir(&#36;path)){ //如果存在&#36;path这个目录 &#36;dir = opendir(&#36;path); //则打开,句柄指向&#36;dir while(&#36;file = readdir(&#36;dir)){ //如果&#36;file---表示读取&#36;dir正确 //则 if(&#36;file=='.'||&#36;file=='..')continue; //上面表示在&#36;file中只有".",或".." //也就是,不会让目录转换出错,---下面那个就是去掉斜杠 if(is_dir(&#36;path.&#36;file))removefile(&#36;path.&#36;file.'/'); else @unlink(&#36;path.&#36;file); // } closedir(&#36;dir); //关闭 下面差不多都是和上面有类似的了。不写了,好累哦。。。 @rmdir(&#36;path); }else @unlink(&#36;path); } function getfilexmltree(&#36;path){ global &#36;domain; &#36;label = split('/', preg_replace('/\/+&#36;/','',&#36;path)); &#36;label = &#36;label[sizeof(&#36;label)-1]; &#36;xmldirs = ''; &#36;xmlfiles = ''; &#36;dir = opendir(&#36;path); while(&#36;file = readdir(&#36;dir)){ if(&#36;file=='.'||&#36;file=='..')continue; if(is_dir(&#36;path.&#36;file))&#36;xmldirs.=getfilexmltree(&#36;path.&#36;file.'/'); else &#36;xmlfiles.='<node label="'.&#36;file.'" path="'.(&#36;path).'" url="'.&#36;domain.'/flexrtf/'.(&#36;path.&#36;file).'" size="'.filesize(&#36;path.&#36;file).'"/>'; } closedir(&#36;dir); return '<node label="'.&#36;label.'" path="'.&#36;path.'" isbranch="true">'.&#36;xmldirs.&#36;xmlfiles.'</node>'; } function logdata(&#36;msg){ &#36;fp = fopen('./data.txt', 'a'); fwrite(&#36;fp, &#36;msg."\n"); fclose(&#36;fp); }

相关问答

更多
  • nl命令在linux系统中用来计算文件中行号。nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等等的功能。 1.命令格式: nl [选项]... [文件]... 2.命令参数: -b :指定行号指定的方式,主要有两种: -b a:表示不论是否为空行,也同样列出行号(类似 cat -n); -b t:如果有空行,空的那一行不要列出行号(默认值); -n :列出行号表示的方法,主要有三种: -n ln:行号在 ...
  • #rm filename.txt;touch filename.txt --------------- 一个命令?再想一想
  • 通过命令+文件名查看内容。如下命令可以查看。 1, cat :由第一行开始显示文件内容; 2,tac:从最后一行开始显示,可以看出tac与cat字母顺序相反; 3,nl:显示的时候输出行号; 4,more:一页一页的显示文件内容; 5,less与more类似,但它可以向前翻页; 6,head:只看前几行; 7,tail:只看最后几行; 8,od:以二进制的方式读取文件。 9,vi和vim作为编辑器,也可以打开文件查看内容。
  • 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 重读
  • QT 我不懂,但 C 是可以的,参考程序: #include #include int main() { FILE *myfile = fopen("test.txt", "w"); char msg[] = " 为中华之崛起而读书"; fwrite(msg, strlen(msg), 1, myfile); fclose(myfile); return 0; }
  • rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除。对于链接文件,只是删除了链接,原有文件均保持不变。 rm是一个危险的命令,使用的时候要特别当心,尤其对于新手,否则整个系统就会毁在这个命令(比如在/(根目录)下执行rm * -rf)。所以,我们在执行rm之前最好先确认一下在哪个目录,到底要删除什么东西,操作时保持高度清醒的头脑。 1.命令格式: rm [选项] 文件… 2.命令功能: 删除一个目录中的一个或多个文件或目录,如果没有使用- ...
  • 下面是读取一个文件 并复制成新文件 #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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)