zoukankan      html  css  js  c++  java
  • linux下用c实现ls命令

    struct dirent中的几个成员:

    d_type:4表示为目录,8表示为文件

    d_reclen:16表示子目录或文件,24表示非子目录

    d_name:目录或文件的名称

    #include <stdio.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <sys/stat.h>
    #include <dirent.h>
    #include <string.h>
    int main(int argc,char* argv[])
    {
         DIR* dir = opendir(".");
         struct dirent* ent=NULL;
         while((ent = readdir(dir)))
         {
             if((ent->d_type == 4||ent->d_type == 8)&&ent->d_name[0]!='.')
             printf("%s  ",ent->d_name);
         }
         closedir(dir);
         puts("");
         return 0;
    }
  • 相关阅读:
    join
    PS1-4
    tftp + bras
    awk调用shell
    curl
    ssh
    查看cp进度,使用watch
    tftp
    scp 链接文件的问题 + tar
    mysql必知必会(三、使用mysql)
  • 原文地址:https://www.cnblogs.com/Ritchie/p/6247854.html
Copyright © 2011-2022 走看看