#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<time.h>
#include<pwd.h>
#include<grp.h>
#include<dirent.h>
#include<errno.h>
#include<string.h>
#include<stdlib.h>
int l_stat(char * p1,char * p);
void a_stat(char * p);
void i_stat(char * p);
void e_dir(char * p);
static long numbers;
//判断是否隐藏文件
int is_spot(const char * p)
{
if(*p == '.')
return ;
else
return ;
}
void e_dir(char * p)
{
struct stat mystat;
DIR * dir;
struct dirent * pd;
int cent = lstat(p,&mystat);
if((mystat.st_mode & S_IFMT) == S_IFDIR)
{
dir = opendir(p);
if(dir == NULL)
{
if(errno)
{
perror("opendir()");
return;
}
}
while()
{
pd = readdir(dir);
if(pd == NULL)
{
if(errno)
{
perror("readdir()");
return ;
}
break;
}
l_stat(p,pd->d_name);
}
closedir(dir);
}
else
l_stat(".",p);
printf("%ldk\n",numbers/);
return ;
}
void h_stat(char * p)
{
struct stat mystat;
DIR * dir;
struct dirent * pd;
int cent = stat(p,&mystat);
if((mystat.st_mode & S_IFMT) == S_IFDIR)
{
dir = opendir(p);
if(dir == NULL)
{
if(errno)
{
perror("opendir()");
return;
}
}
while()
{
pd = readdir(dir);
if(pd == NULL)
{
if(errno)
{
perror("readdir()");
return ;
}
break;
}
if(is_spot(pd->d_name) == )
printf("%s \n",pd->d_name);
}
closedir(dir);
}
else
printf("%s \n",p);
return;
}
int main(int argc,char ** argv)
{
if(argc < )
return ;
char * op = "-laih";
int s;
while()
{
s = getopt(argc,argv,op);
if(s == -)
break;
switch(s)
{
case 'l':e_dir(argv[]); break;
case 'a':a_stat(argv[]);break;
case 'i':i_stat(argv[]);break;
case 'h':h_stat(argv[]);break;
case '?':printf("无该选项\n");break;
// case 1 : printf("%s\n",argv[2]);break;
default:break;
}
}
return ;
}
void i_stat(char * p)
{
struct stat mystat;
int nodenumber;
DIR * dir;
struct dirent * pd;
int cent = stat(p,&mystat);
if((mystat.st_mode & S_IFMT) == S_IFDIR)
{
dir = opendir(p);
if(dir == NULL)
{
if(errno)
{
perror("opendir()");
return;
}
}
while()
{
pd = readdir(dir);
if(pd == NULL)
{
if(errno)
{
perror("readdir()");
return ;
}
break;
}
if(is_spot(pd->d_name) == )
{
printf("%ld ",pd->d_ino);
printf("%s\n",pd->d_name);
}
}
closedir(dir);
}
else
{
printf("%ld ",mystat.st_ino);
printf("%s\n",p);
}
}
void a_stat(char * p)
{
struct stat mystat;
DIR * dir;
struct dirent * pd;
int cent = stat(p,&mystat);
if((mystat.st_mode & S_IFMT) == S_IFDIR)
{
dir = opendir(p);
if(dir == NULL)
{
if(errno)
{
perror("opendir()");
return;
}
}
while()
{
pd = readdir(dir);
if(pd == NULL)
{
if(errno)
{
perror("readdir()");
return ;
}
break;
}
printf("%s ",pd->d_name);
}
}
else
printf("%s ",p);
}
// 追加/获得路径
char * dir_cat(const char * p,const char * buf)
{
char * buf_cat = malloc();
memset(buf_cat,'\0',);
strcpy(buf_cat,p);
buf_cat[strlen(buf_cat)] = '/';
strcat(buf_cat,buf);
return buf_cat;
}
//获取文件属性
int l_stat(char * p,char * p_name)
{
struct tm * tmp = NULL;
struct passwd * pwd = NULL;
struct group * wd = NULL;
struct stat mystat;
char buf[];
char * p1;
int cnt;
p1 = dir_cat(p,p_name);
cnt = stat(p1,&mystat);
if(cnt == -)
{
perror("stat()");
return -;
}
//判断是不是隐藏文件
if(is_spot(p_name) == )
{
numbers += mystat.st_blocks;
switch(mystat.st_mode & S_IFMT)
{
case S_IFREG: putchar('-');break;
case S_IFBLK: putchar('b');break;
case S_IFDIR: putchar('d');break;
case S_IFCHR: putchar('c');break;
case S_IFIFO: putchar('p');break;
default:break;
}
//拥有者
if(mystat.st_mode & S_IRUSR)
putchar('r');
else
putchar('-');
if(mystat.st_mode & S_IWUSR)
putchar('w');
else
putchar('-');
if(mystat.st_mode & S_IXUSR)
putchar('x');
else
putchar('-');
//所属组
if(mystat.st_mode & S_IRGRP)
putchar('r');
else
putchar('-');
if(mystat.st_mode & S_IWGRP)
putchar('w');
else
putchar('-');
if(mystat.st_mode & S_IXGRP)
putchar('x');
else
putchar('-');
//其他
if(mystat.st_mode & S_IROTH)
putchar('r');
else
putchar('-');
if(mystat.st_mode & S_IWOTH)
putchar('w');
else
putchar('-');
if(mystat.st_mode & S_IXOTH)
putchar('x');
else
putchar('-');
//硬链接个数
printf("%2ld ",mystat.st_nlink);
//文件拥有者名字
pwd = getpwuid(mystat.st_uid);
printf("%s ",pwd->pw_name);
//文件所属组
wd = getgrgid(mystat.st_gid);
printf("%s ",wd->gr_name);
//总字节个数
printf("%5ld ",mystat.st_size);
//获取时间
tmp = localtime(&mystat.st_mtim.tv_sec);
strftime(buf,,"%m 月 %d %H:%M",tmp);
printf("%s ",buf);
//文件名
printf("%s\n",p_name);
}
return ;
}

homework 张一刚的更多相关文章

  1. HDU 1789 Doing Homework again(贪心)

    Doing Homework again 这只是一道简单的贪心,但想不到的话,真的好难,我就想不到,最后还是看的题解 [题目链接]Doing Homework again [题目类型]贪心 & ...

  2. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  3. HUST 1555 A Math Homework

    1555 - A Math Homework 时间限制:1秒 内存限制:128兆 338 次提交 131 次通过 题目描述     QKL is a poor and busy guy, and he ...

  4. Doing Homework again(杭电1789)

    Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. kuangbin专题十二 HDU1074 Doing Homework (状压dp)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  6. 刚接触Linux,菜鸟必备的小知识点(一)

    身为一个将要大四的学生,而且还是学计算机的没有接触过linux简直是羞愧难当.这个假期做了一个软件测试员,必须要熟悉linux的操作,所以对于我这个菜鸟我也就说几点比较重要的小知识点吧. 第一.cd指 ...

  7. bzoj 4320: ShangHai2006 Homework

    4320: ShangHai2006 Homework Time Limit: 10 Sec Memory Limit: 128 MB Description 1:在人物集合 S 中加入一个新的程序员 ...

  8. day4(homework)

    第八单元 1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) 2) 将用户信息数据库文件和用户密码数据库文件纵向合并为一个文件/2.txt(追加) 3) 将/1.txt ...

  9. 刚写完的商城erp + 这个商城前台,新鲜出炉。自己1个人写, 包括php框架和前端html页面.

    刚写完的商城erp + 这个商城前台,新鲜出炉.自己1个人写, 包括php框架和前端html页面. 刚写完的商城erp + 这个商城前台,新鲜出炉.自己1个人写, 包括php框架和前端html页面.

随机推荐

  1. 搭建NTP服务集群、高可用

    1.原理 Keepalived 的作用是检测后端服务器的状态,如果有一台服务器死机,或工作出现故障,Keepalived 将检测到,并将有故障的服务器从系统中剔除.当服务器工作正常后 Keepaliv ...

  2. 启动fiddler导致浏览器无法上网的解决方法

    1. 开发fiddler,进入Tools->Fiddler Tools,按照如图3部配置,即可实现无法上网的问题. 2. 见图1: 3.见图2: 4.见图3. 4. 完成以上配置后,重启fidd ...

  3. RabbitMQ中的RPC实现

    1.RPC简述 RPC,Remote Procedure Call 远程过程调用.通俗讲,两段程序不在同一个内存空间,无法直接通过方法名调用,就需要通过网络通信方式调用.对于RabbitMQ,本身就是 ...

  4. ionic 3.0中使用原生插件ionic-native

    作为一个ionic的新手,今天使用了ionic的原生粘贴板插件  @ionic-native/clipboard,根据ionic官方文档上执行的命令 $ ionic cordova plugin ad ...

  5. PHP基本随笔

    1:制作一个永不重复的数字: private function getMillisecond(){ list($t1, $t2) = explode(' ', microtime()); return ...

  6. nginx 支持ipv6设置

    为了使nginx支持ipv6 访问需要做以下配置: 1.找到nginx的安装路径: 使用命令:whereis nginx 查看nginx安装路径: 进入nginx执行文件目录: 先用./nginx - ...

  7. 【leetcode】461. Hamming Distance

    problem 461. Hamming Distance solution1: 根据题意,所求汉明距离指的是两个数字的二进制对应位不同的个数.对应位异或操作为1的累积和. class Solutio ...

  8. 【软件安装与环境配置】TX2安装配置caffe过程

    Tx2刷机 sudo sh ./caffe_dependency.sh 注意python的版本问题. 问题 LD -o .build_release/lib/libcaffe.so. /usr/bin ...

  9. JMeter中Ultimate Thread Group插件使用

    JMeter下载地址:  http://jmeter.apache.org/Ultimate Thread Group插件下载地址: https://jmeter-plugins.org/get/ 一 ...

  10. FixedUpdate()使用

    当MonoBehaviour启用时,其 FixedUpdate在每一帧被调用. 处理Rigidbody时,需要用FixedUpdate代替Update.例如:给刚体加一个作用力时,你必须应用作用力在F ...