UNIX環境高級編程學習之第四章文件和目錄-用C實現Shell中的"ls -l"功能
// 只能查看目錄中的所有文件屬性 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> int main(int argc, char *argv[]) { char szDirPath[512] = { 0 }; char szFilePath[512] = { 0 }; DIR * pDIR; if (argc > 1) { strcpy(szDirPath, argv[1]); }else { strcpy(szDirPath, "."); } pDIR = opendir(szDirPath); if (NULL == pDIR) { printf("Open DIR[%s] Error! /n", szDirPath); return -1; } struct dirent* pdirent; int n = 0; int i; int y; char szName[256]; char szLineData[512]; struct stat file_stat; while ( (pdirent = readdir(pDIR)) != NULL) { memset(szName, 0, sizeof(szName)); memset(szLineData, 0, sizeof(szLineData)); memset(szFilePath, 0, sizeof(szFilePath)); memset(&file_stat, '/0', sizeof(file_stat)); strcpy(szName, pdirent->d_name); sprintf(szFilePath, "%s/%s", szDirPath, szName); stat(szFilePath, &file_stat); time_t t = file_stat.st_mtime; int len = strlen(szName); if (pdirent->d_type == DT_DIR) // 文件夾 { szName[len] = '//'; }else if (pdirent->d_type == DT_DIR) // 符號連接 { szName[len] = '@'; } sprintf(szLineData, "%-32s uid=%-8u gid=%-8u LastDate=%s ", szName, file_stat.st_uid, file_stat.st_gid, ctime(&t)); printf(szLineData); } printf("/n"); closedir(pDIR); return 0; }
UNIX環境高級編程學習之第十一章線程-線程的創建、退出、等待、取消、分離 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #i
UNIX環境高級編程學習之第五章標準IO-實現查看所有用戶 #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(i
UNIX環境高級編程學習之第六章系統數據文件和信息-修改第四章實現的Shell的“ls -l”功能, 加入顯示文件的用戶名和組名 // 只能查看目錄中的所有文件屬性 #include <stdio.h> #include <stdlib.
UNIX環境高級編程學習之第十章信號-信號集的操作,讓進程阻塞SIGQUIT信號 /* File: sigprocmask.c Desc: 信號集的操作,讓進程阻塞SIGQUIT信號 */ #include <stdio.h> #in
UNIX環境高級編程學習之第八章進程控制-用父子進程實現打開kate,返回kate關閉狀態 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unis
UNIX環境高級編程學習之第三章文件IO-文件讀操作 #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include
UNIX環境高級編程學習之第十章信號-信號的基本操作(綁定/忽略/默認/發送) /* File: signal.c Desc: 信號基本操作 */ #include <stdio.h> #include <stdlib.h> #inc
到現在,我Unix,數據庫的掃盲基本完成了,就差網絡這一塊了。從今天開始網絡掃盲。上週五開始看HTTPD的實現,我們的httpd是AA(AA是我們SBE的元老之一)開發的,只要是AA開發的東西,學習一遍都很有收穫。因爲AA是一位非常優秀的