关于linux重定向的使用

ls -a    #不忽略前面带.的文件、目录

ls -l #长列表模式,列出的信息多

ls -a > 1.txt    #把stdout重定向到1.txt文件中,覆写

ls -a >> 1.txt    #把stdout重定向到1.txt文件中,追加

重定向:对原来系统命令的默认执行方式进行改变,比如在命令行中输入ls,会在屏幕中显示出当前目录,但如果输入ls > 1.txt,会把本该在屏幕中显示的目录写到文件中。

一、命令行中使用:


二、在程序中调用system

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int rs = system("ls > 2.txt");
    if(rs < 0)
        exit(1);
    return 0;       
}



猜你喜欢

转载自blog.csdn.net/znzxc/article/details/80457539