voc智能锁安装视频寿命多长呀?

ls命令文件名后面那个*号代表啥意思?_ubuntu吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:103,779贴子:
ls命令文件名后面那个*号代表啥意思?收藏
ui培训哪个好,0基础+双证+实战「就业无忧」
info ls//找到
--classify
通配符,带该名的所有文件
ls格式:ls [参数] [文件/目录]参数说明:-a 表示列出所有的文件,包括以"."开头的隐藏文件-d 如果其后接的是一个目录,则此只输出目录的名称-l 表示以清单的形式列出文件的条目,包括文件的名称、权限、拥有者、大小、最后修改时间等-t 表示列出的条目按最后修改的时间进行排序,默认是使用文件夹的名称来排序-C 以文件的名称按列纵向排序-F 在文件名后加一个符号来表示文件类型 *代表这些文件是可执行文件
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或Linux(69)
ls 命令可以说是Linux下最常用的命令之一。它有众多的选项,其中有很多是很有用的,你是否熟悉呢?要学习如何编写 ls 命令,首先我们要先了解它怎么使用。
我们在&&第一节中就已经提到过 ls 命令的使用,下面我们先就 ls 命令做详细的介绍
1.ls命令详细介绍
下面列出了 ls 命令的绝大多数选项。&  
  -a 列出目录下的所有文件,包括以 . 开头的隐含文件。&
  -b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出。&
  -c 输出文件的 i 节点的修改时间,并以此排序。&
  -d 将目录象文件一样显示,而不是显示其下的文件。&
  -e 输出时间的全部信息,而不是输出简略信息。&
  -f -U 对输出的文件不排序。&
  -g 无用。&
  -i 输出文件的 i 节点的索引信息。&
  -k 以 k 字节的形式表示文件的大小。&
  -l 列出文件的详细信息。&
  -m 横向输出文件名,并以“,”作分格符。&
  -n 用数字的 UID,GID 代替名称。&
  -o 显示文件的除组信息外的详细信息。&
&&&&&&& -F 在每个文件名后附上一个字符以说明该文件的类型,“*”表示可执行的普通&
  文件;“/”表示目录;“@”表示符号链接;“|”表示FIFOs;“=”表示套&
  接字(sockets)。&
  -q 用?代替不可输出的字符。&
  -r 对目录反向排序。&
  -s 在每个文件名后输出该文件的大小。&
  -t 以时间排序。&
  -u 以文件上次被访问的时间排序。&
  -x 按列输出,横向排序。&
  -A 显示除 “.”和“..”外的所有文件。&
  -B 不输出以 “~”结尾的备份文件。&
  -C 按列输出,纵向排序。&
  -G 输出文件的组的信息。&
  -L 列出链接文件名而不是链接到的文件。&
  -N 不限制文件长度。&
  -Q 把输出的文件名用双引号括起来。&
  -R 列出所有子目录下的文件。&
  -S 以文件大小排序。&
  -X 以文件的扩展名(最后一个 . 后的字符)排序。&
  -1 一行只输出一个文件。&
  --color=no 不显示彩色文件名&
  --help 在标准输出上显示帮助信息。&
  --version 在标准输出上输出版本信息并退出。
&---------------------------------------------------------------------
2.ls命令实现过程用到的函数
函数原型:
1)int stat(const char *path, struct stat *buf);
  stat函数 将path(文件)的属性信息保存在 buf结构体中
2)struct passwd *getpwuid(uid_t uid);
  getpwuid函数是通过用户的uid查找用户的passwd数据,其中包括username
3)struct group *getgrgid(gid_t gid);
  getgrgid函数通过用户组gid指定的组识别码逐一搜索组文件,找到时便将该组的数据以group结构返回。
4)struct tm *localtime(const time_t *timep);
&  localtime函数把从零点零分到当前时间系统所偏移的秒数时间转换为日历时间 。并且此函数获得的tm结构体的时间,是已经进行过时区转化为本地时间。
5) &DIR *opendir(const char *name);
  opendir()函数的作用是:打开目录句柄,返回一个文件描述符。
6) &struct dirent *readdir(DIR *dirp);
  readdir()函数读取一个目录文件描述符的信息,将信息返回到dirent结构体中。
struct stat 内容:
/* The stat structure.
struct stat {
unsigned long
/* Device.
unsigned long
/* File serial number.
unsigned int
/* File mode.
unsigned int
/* Link count.
unsigned int
/* User ID of the file's owner.
unsigned int
/* Group ID of the file's group. */
unsigned long
/* Device number, if device.
unsigned long
/* Size of file, in bytes.
/* Optimal block size for I/O.
/* Number 512-byte blocks allocated. */
/* Time of last access.
unsigned int
/* Time of last modification.
unsigned int
/* Time of last status change.
unsigned int
unsigned int
__unused4;
unsigned int
__unused5;
struct stat中的st_mode值各个位代表的意思:
The following flags are defined for the st_mode field:
      /*
是什么类型的文件
<span style="color:#70000
bit mask for the file type bit fields
<span style="color:#40000
<span style="color:#20000
symbolic link
<span style="color:#00000
regular file
<span style="color:#60000
block device
<span style="color:#40000
<span style="color:#20000
character device
<span style="color:#10000
<span style="color:#04000
set UID bit
<span style="color:#02000
set-group-ID bit (see below)
<span style="color:#01000
sticky bit (see below)
      /*
是否有可读写权限
<span style="color:#700
mask for file owner permissions
<span style="color:#400
owner has read permission
<span style="color:#200
owner has write permission
<span style="color:#100
owner has execute permission
<span style="color:#070
mask for group permissions
<span style="color:#040
group has read permission
<span style="color:#020
group has write permission
<span style="color:#010
group has execute permission
<span style="color:#007
mask for permissions for others (not in group)
<span style="color:#004
others have read permission
<span style="color:#002
others have write permission
<span style="color:#001
others have execute permission
struct passwd 内容:
/* The passwd structure.
struct passwd
/* Username.
/* Password.
__uid_t pw_
/* User ID.
__gid_t pw_
/* Group ID.
/* Real name.
/* Home directory.
/* Shell program.
struct group 内容:
/* The group structure.
struct group
/* Group name.
/* Password.
__gid_t gr_
/* Group ID.
char **gr_
/* Member list.
struct tm 内容:
/* Used by other time functions.
/* Seconds.
[0-60] (1 leap second) */
/* Minutes.
/* Day of week.
/* Days in year.[0-365]
[-1/0/1]*/
long int tm_
/* Seconds east of UTC.
__const char *tm_
/* Timezone abbreviation.
long int __tm_
/* Seconds east of UTC.
__const char *__tm_
/* Timezone abbreviation.
struct dirent内容:
struct dirent
#ifndef __USE_FILE_OFFSET64
__ino_t d_
__off_t d_
__ino64_t d_
__off64_t d_
unsigned short int d_
unsigned char d_
char d_name[<span style="color:#6];
/* We must not include limits.h! */
&---------------------------------------------------------------------
3.ls命令的实现
1)首先获得文件的属性
const char *path由main函数传入:
int main(int argc, char **argv)
获取文件argv[1]的属性信息,并保存在st结构体中:
if(stat(argv[<span style="color:#], &st) & <span style="color:#)
perror(&stat&);
return -<span style="color:#;
2)判断是否是目录
if((st.st_mode & S_IFMT) == S_IFDIR)
display_dir(argv[<span style="color:#]);
display_file(argv[<span style="color:#], argv[<span style="color:#]);
如果是文件则直接获取文件信息即可,如果是目录则要进入到目录中进行遍历,我们封装两个函数display_file()和display_dir()来分别实现
3)目录与文件的实现
【display_file()】
a.由属性信息获得文件的类型&
用stat结构体中的st_mode与掩码S_IFMT相与,得到文件类型:
switch(st.st_mode & S_IFMT)
case S_IFREG:
printf(&-&);
case S_IFDIR:
printf(&d&);
case S_IFLNK:
printf(&l&);
case S_IFBLK:
printf(&b&);
case S_IFCHR:
printf(&c&);
case S_IFIFO:
printf(&p&);
case S_IFSOCK: printf(&s&);
&b.由属性信息获得文件的可读写权限
for(i = <span style="color:#; i &= <span style="color:#; i--)
if(st.st_mode & (<span style="color:# && i))
switch(i%<span style="color:#)
case <span style="color:#: printf(&r&); break;
case <span style="color:#: printf(&w&); break;
case <span style="color:#: printf(&x&); break;
printf(&-&);
c.由属性信息获得文件的owner和所在的group信息
pw = getpwuid(st.st_uid);
gr = getgrgid(st.st_gid);
d.最后文件所以信息可以打印
printf(&%2d %s %s %4ld&, st.st_nlink, pw-&pw_name, gr-&gr_name, st.st_size);
tm = localtime(&st.st_ctime);
printf(& %04d-%02d-%02d %02d:%02d&,tm-&tm_year &#43; <span style="color:#00, tm-&tm_mon &#43; <span style="color:#, tm-&tm_mday, tm-&tm_hour, tm-&tm_min);
printf(& %s\n&, filename);
【display_dir()】
获取目录文件描述符,并且读取目录信息,判断目录不为空则继续读取。如果读取到的是目录,则递归调用,否则直接调用display_file()即可。
dir = opendir(dirname);
while((dirent = readdir(dir)) != NULL)
strcpy(buf, dirname);
strcat(buf, &/&);
strcat(buf, dirent-&d_name);
if(stat(buf, &st))
perror(&stat&);
return -<span style="color:#;
if(dirent-&d_name[<span style="color:#] != '.')
display_file(buf, dirent-&d_name);
&---------------------------------------------------------------------
4.结果显示
查看文件(display_file)结果:
linux@ubuntu:~/test$ ./a.out stat.c
-rw-r--r-- <span style="color:# linux linux <span style="color:#316 <span style="color:#12-<span style="color:#-<span style="color:# <span style="color:#:<span style="color:# stat.c
查看文件夹(display_dir)结果:
linux@ubuntu:~/test$ ./a.out .
-rw-r--r-- <span style="color:# linux linux <span style="color:#08 <span style="color:#12-<span style="color:#-<span style="color:# <span style="color:#:<span style="color:# ls.c
-rw-r--r-- <span style="color:# linux linux <span style="color:#35 <span style="color:#12-<span style="color:#-<span style="color:# <span style="color:#:<span style="color:# ls-bak.c
-rwxrw-rw- <span style="color:# linux linux <span style="color:#77 <span style="color:#12-<span style="color:#-<span style="color:# <span style="color:#:<span style="color:# ls_t.c
-rw-r--r-- <span style="color:# linux linux <span style="color:#316 <span style="color:#12-<span style="color:#-<span style="color:# <span style="color:#:<span style="color:# stat.c
-rwxr-xr-x <span style="color:# linux linux <span style="color:#32 <span style="color:#12-<span style="color:#-<span style="color:# <span style="color:#:<span style="color:# a.out
附:ls 命令实现的完整代码
#include &stdio.h&
#include &sys/types.h&
#include &dirent.h&
#include &sys/stat.h&
#include &string.h&
#include &unistd.h&
#include &grp.h&
#include &pwd.h&
#include &time.h&
int display_file(char *path, char *filename)
struct passwd *
struct group *
struct tm *
stat(path, &st);
switch(st.st_mode & S_IFMT)
case S_IFREG:
printf(&-&);
case S_IFDIR:
printf(&d&);
case S_IFLNK:
printf(&l&);
case S_IFBLK:
printf(&b&);
case S_IFCHR:
printf(&c&);
case S_IFIFO:
printf(&p&);
case S_IFSOCK: printf(&s&);
for(i = <span style="color:#; i &= <span style="color:#; i--)
if(st.st_mode & (<span style="color:# && i))
switch(i%<span style="color:#)
case <span style="color:#: printf(&r&); break;
case <span style="color:#: printf(&w&); break;
case <span style="color:#: printf(&x&); break;
printf(&-&);
pw = getpwuid(st.st_uid);
gr = getgrgid(st.st_gid);
printf(&%2d %s %s %4ld&, st.st_nlink, pw-&pw_name, gr-&gr_name, st.st_size);
tm = localtime(&st.st_ctime);
printf(& %04d-%02d-%02d %02d:%02d&,tm-&tm_year &#43; <span style="color:#00, tm-&tm_mon &#43; <span style="color:#, tm-&tm_mday, tm-&tm_hour, tm-&tm_min);
printf(& %s\n&, filename);
return <span style="color:#;
int display_dir(char *dirname)
struct dirent *
char buf[<span style="color:#24];
dir = opendir(dirname);
while((dirent = readdir(dir)) != NULL)
strcpy(buf, dirname);
strcat(buf, &/&);
strcat(buf, dirent-&d_name);
if(stat(buf, &st))
perror(&stat&);
return -<span style="color:#;
if(dirent-&d_name[<span style="color:#] != '.')
display_file(buf, dirent-&d_name);
int main(int argc, char **argv)
char buf[<span style="color:#24];
if(stat(argv[<span style="color:#], &st) & <span style="color:#)
perror(&stat&);
return -<span style="color:#;
if((st.st_mode & S_IFMT) == S_IFDIR)
display_dir(argv[<span style="color:#]);
display_file(argv[<span style="color:#], argv[<span style="color:#]);
return <span style="color:#;
关于如何显示文件颜色的相关介绍可以参看:
效果图如下:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:367891次
积分:4673
积分:4673
排名:第4986名
原创:58篇
转载:311篇
评论:18条
(1)(4)(3)(1)(2)(1)(2)(3)(2)(2)(8)(24)(3)(8)(1)(2)(3)(18)(11)(13)(1)(21)(60)(31)(5)(1)(3)(7)(5)(6)(5)(17)(35)(2)(2)(8)(7)(6)(18)(1)(20)Ubuntu 编写自己的ls命令
第2页_Linux教程_Linux公社-Linux系统门户网站
你好,游客
Ubuntu 编写自己的ls命令
来源:Linux社区&
作者:lr-ting
2.ls命令实现过程用到的函数
函数原型:
1)int stat(const char *path, struct stat *buf);
  stat函数 将path(文件)的属性信息保存在 buf结构体中
2)struct passwd *getpwuid(uid_t uid);
  getpwuid函数是通过用户的uid查找用户的passwd数据,其中包括username
3)struct group *getgrgid(gid_t gid);
  getgrgid函数通过用户组gid指定的组识别码逐一搜索组文件,找到时便将该组的数据以group结构返回。
4)struct tm *localtime(const time_t *timep);
&  localtime函数把从零点零分到当前时间系统所偏移的秒数时间转换为日历时间 。并且此函数获得的tm结构体的时间,是已经进行过时区转化为本地时间。
5) &DIR *opendir(const char *name);
  opendir()函数的作用是:打开目录句柄,返回一个文件描述符。
6) &struct dirent *readdir(DIR *dirp);
  readdir()函数读取一个目录文件描述符的信息,将信息返回到dirent结构体中。
struct stat 内容:
/* The stat structure.
struct stat {
unsigned long
/* Device.
unsigned long
/* File serial number.
unsigned int
/* File mode.
unsigned int
/* Link count.
unsigned int
/* User ID of the file's owner.
unsigned int
/* Group ID of the file's group. */
unsigned long
/* Device number, if device.
unsigned long
/* Size of file, in bytes.
/* Optimal block size for I/O.
/* Number 512-byte blocks allocated. */
/* Time of last access.
unsigned int
/* Time of last modification.
unsigned int
/* Time of last status change.
unsigned int
unsigned int
__unused4;
unsigned int
__unused5;
struct stat中的st_mode值各个位代表的意思:
The following flags are defined for the st_mode field:
      /*
是什么类型的文件
<SPAN style="COLOR: #70000
bit mask for the file type bit fields
<SPAN style="COLOR: #40000
<SPAN style="COLOR: #20000
symbolic link
<SPAN style="COLOR: #00000
regular file
<SPAN style="COLOR: #60000
block device
<SPAN style="COLOR: #40000
<SPAN style="COLOR: #20000
character device
<SPAN style="COLOR: #10000
<SPAN style="COLOR: #04000
set UID bit
<SPAN style="COLOR: #02000
set-group-ID bit (see below)
<SPAN style="COLOR: #01000
sticky bit (see below)      /*
是否有可读写权限
<SPAN style="COLOR: #700
mask for file owner permissions
<SPAN style="COLOR: #400
owner has read permission
<SPAN style="COLOR: #200
owner has write permission
<SPAN style="COLOR: #100
owner has execute permission
<SPAN style="COLOR: #070
mask for group permissions
<SPAN style="COLOR: #040
group has read permission
<SPAN style="COLOR: #020
group has write permission
<SPAN style="COLOR: #010
group has execute permission
<SPAN style="COLOR: #007
mask for permissions for others (not in group)
<SPAN style="COLOR: #004
others have read permission
<SPAN style="COLOR: #002
others have write permission
<SPAN style="COLOR: #001
others have execute permission
struct passwd 内容:
/* The passwd structure.
struct passwd
/* Username.
/* Password.
__uid_t pw_
/* User ID.
__gid_t pw_
/* Group ID.
/* Real name.
/* Home directory.
/* Shell program.
struct group 内容:
/* The group structure.
struct group
/* Group name.
/* Password.
__gid_t gr_
/* Group ID.
char **gr_
/* Member list.
struct tm 内容:
/* Used by other time functions.
/* Seconds.
[0-60] (1 leap second) */
/* Minutes.
/* Day of week.
/* Days in year.[0-365]
[-1/0/1]*/
long int tm_
/* Seconds east of UTC.
__const char *tm_
/* Timezone abbreviation.
long int __tm_
/* Seconds east of UTC.
__const char *__tm_
/* Timezone abbreviation.
struct dirent内容:
struct dirent
#ifndef __USE_FILE_OFFSET64
__ino_t d_
__off_t d_
__ino64_t d_
__off64_t d_
unsigned short int d_
unsigned char d_
char d_name[<SPAN style="COLOR: #6];
/* We must not include limits.h! */
相关资讯 & & &
& (04/03/:21)
& (03/14/:46)
& (09/12/:30)
& (10/23/:19)
& (02/01/:05)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款2010年12月 C/C++大版内专家分月排行榜第三
2011年1月 Linux/Unix社区大版内专家分月排行榜第二2010年12月 Linux/Unix社区大版内专家分月排行榜第二2010年11月 Linux/Unix社区大版内专家分月排行榜第二
2011年11月 Linux/Unix社区大版内专家分月排行榜第三2011年10月 Linux/Unix社区大版内专家分月排行榜第三2011年6月 Linux/Unix社区大版内专家分月排行榜第三2011年5月 Linux/Unix社区大版内专家分月排行榜第三2011年4月 Linux/Unix社区大版内专家分月排行榜第三2011年3月 Linux/Unix社区大版内专家分月排行榜第三2011年2月 Linux/Unix社区大版内专家分月排行榜第三2010年5月 Linux/Unix社区大版内专家分月排行榜第三
2011年1月 Linux/Unix社区大版内专家分月排行榜第二2010年12月 Linux/Unix社区大版内专家分月排行榜第二2010年11月 Linux/Unix社区大版内专家分月排行榜第二
2011年11月 Linux/Unix社区大版内专家分月排行榜第三2011年10月 Linux/Unix社区大版内专家分月排行榜第三2011年6月 Linux/Unix社区大版内专家分月排行榜第三2011年5月 Linux/Unix社区大版内专家分月排行榜第三2011年4月 Linux/Unix社区大版内专家分月排行榜第三2011年3月 Linux/Unix社区大版内专家分月排行榜第三2011年2月 Linux/Unix社区大版内专家分月排行榜第三2010年5月 Linux/Unix社区大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。}

我要回帖

更多关于 voc指纹锁suododo 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信