欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mysate中stat命令的實(shí)現(xiàn)方法

 更新時(shí)間:2022年10月15日 11:45:21   作者:戴駿  
這篇文章主要介紹了mysate中stat命令的實(shí)現(xiàn)方法,stat作用:用來(lái)顯示文件的詳細(xì)信息,包括inode, atime, mtime, ctime,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下

一、stat(1)

  • stat作用:用來(lái)顯示文件的詳細(xì)信息,包括inode, atime, mtime, ctime
  • stat格式:stat [OPTION]…FILE…
  • stat命令格式:
    • -L:顯示符號(hào)鏈接
    • -f:顯示文件所在的文件系統(tǒng)信息
    • -t:以簡(jiǎn)潔的方式輸出摘要信息
  • stat輸出內(nèi)容:
    • File:顯示文件名
    • Size:顯示文件大小
    • Blocks:文件使用的數(shù)據(jù)塊總數(shù)
    • IO Block:IO塊大小
    • regular file:文件類(lèi)型(常規(guī)文件)
    • Device:設(shè)備編號(hào)
    • Inode:Inode號(hào)
    • Links:鏈接數(shù)
    • Access:文件的權(quán)限
    • Gid、Uid:文件所有權(quán)的Gid和Uid
  • 學(xué)習(xí)截圖

二、man -k ,grep -r的使用

三、偽代碼

聲明結(jié)構(gòu)體
讀入命令行文件路徑
調(diào)用stat()函數(shù)給結(jié)構(gòu)體賦值
逐個(gè)打印結(jié)構(gòu)體中的數(shù)據(jù)

四、產(chǎn)品代碼 mystate.c的碼云鏈接

#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    struct stat sb;
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    if (stat(argv[1], &sb) == -1) {
        perror("stat");
        exit(EXIT_FAILURE);
    }
    printf("File type:                ");
    switch (sb.st_mode & S_IFMT) {
        case S_IFBLK:   printf("block device\n");
            break;
    case S_IFCHR:   printf("character device\n");
            break;
    case S_IFDIR:   printf("directory\n");
            break;
    case S_IFIFO:   printf("FIFO/pipe\n");
            break;
    case S_IFLNK:   printf("symlink\n");
            break;
    case S_IFREG:   printf("regular file\n");
            break;
    case S_IFSOCK:  printf("socket\n");
            break;
    default:        printf("unknown?\n");
            break;
    }
    printf("I-node number:            %ld\n", (long) sb.st_ino);
    printf("Mode:                     %lo (octal)\n",(unsigned long) sb.st_mode);
    printf("Link count:               %ld\n", (long) sb.st_nlink);
    printf("Ownership:                UID=%ld   GID=%ld\n",(long) sb.st_uid, (long) sb.st_gid);
    printf("Preferred I/O block size: %ld bytes\n",(long) sb.st_blksize);
    printf("File size:                %lld bytes\n",(long long) sb.st_size);
    printf("Blocks allocated:         %lld\n",(long long) sb.st_blocks);
    printf("Last status change:       %s", ctime(&sb.st_ctime));
    printf("Last file access:         %s", ctime(&sb.st_atime));
    printf("Last file modification:   %s", ctime(&sb.st_mtime));
    exit(EXIT_SUCCESS);
}

五、測(cè)試代碼,mystat 與stat(1)對(duì)比

到此這篇關(guān)于mysate中stat命令的實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)mysate中stat命令內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論