自定义mac的ll命令
2015-08-01 00:00
239 查看
摘要: mac本身不自带ll命令,而每次都要使用ls -l显得特别麻烦。所以附上下面的源代码。大家可以自行编译成ll命令
#include<stdio.h> #include<time.h> #include<sys/types.h> #include<dirent.h> #include<sys/stat.h> #include<stdlib.h> #include<.h> do_ls([]); dostat( *); show_file_info( *, stat *); mode_to_letters(,[]); * uid_to_name(uid_t); * gid_to_name(gid_t); main( argc, *argv[]){ (argc==) do_ls(); printf(); } do_ls( dirname[]){ DIR *dir_ptr; dirent *direntp; ((dir_ptr=opendir(dirname))==) fprintf(stderr,,dirname); { ((direntp=readdir(dir_ptr))!=) dostat(direntp->d_name); closedir(dir_ptr); } } dostat( *filename){ stat info; (lstat(filename,&info)==-) perror(); show_file_info(filename,&info); } show_file_info( *filename, stat *info_p){ modestr[]; mode_to_letters(info_p->st_mode,modestr); printf(,modestr); printf(,()info_p->st_nlink); printf(,uid_to_name(info_p->st_uid)); printf(,gid_to_name(info_p->st_gid)); printf(,()info_p->st_size); time_t timelong=info_p->st_mtime; tm *htime=localtime(&timelong); printf(,htime->tm_year+,htime->tm_mon+,htime->tm_mday,htime->tm_hour,htime->tm_min); printf(,filename); } mode_to_letters( mode, str[]){ strcpy(str,); (S_ISDIR(mode)) str[]=; (S_ISCHR(mode)) str[]=; (S_ISBLK(mode)) str[]=; (mode & S_IRUSR) str[]=; (mode & S_IWUSR) str[]=; (mode & S_IXUSR) str[]=; (mode & S_IRGRP) str[]=; (mode & S_IWGRP) str[]=; (mode & S_IXGRP) str[]=; (mode & S_IROTH) str[]=; (mode & S_IWOTH) str[]=; (mode & S_IXOTH) str[]=; } #include<pwd.h> * uid_to_name(uid_t uid){ passwd *pw_str; numstr[]; ((pw_str=getpwuid(uid))==NULL){ sprintf(numstr,,uid); numstr; } pw_str->pw_name; } #include<grp.h> * gid_to_name(gid_t gid){ group *grp_ptr; numstr[]; ((grp_ptr=getgrgid(gid))==NULL){ sprintf(numstr,,gid); numstr; } grp_ptr->gr_name; }
相关文章推荐
- 什么是Mac OS X?跟Linux有什么区别
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- Linux vs Mac:Linux 比 Mac 好的 7 个原因
- 苹果mac OS X上安装metasploit
- Validation of viewstate MAC failed.的解决方法
- Mac平台中编译安装Lua运行环境及Hello Lua实例
- 在Mac OS中安装Lua的教程
- vbs Windows系统改变或修改网卡的MAC地址的脚本与软件第1/2页
- MAC官方菜单纯CSS实现灰色会换色
- 在Mac OS下使用Node.js的简单教程
- Mac环境下php操作mysql数据库的方法分享
- PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码
- jQuery根据用户电脑是mac还是pc加载对应样式的方法
- 在MAC OS X上安装MYSQL
- Shell脚本获取本地网卡IP、mac地址、子网掩码、dns IP、外网IP
- MAC系统中添加MYSQL开机启动的方法
- MAC 系统如何使用 Sublime Text 2 直接编译运行 java 代码
- mac下安装nginx和php
- linux中mac地址绑定方法