60 likes | 179 Vues
This guide provides a clear explanation of the CHOWN and STAT commands in Linux programming. CHOWN is utilized to change the owner or group of a file, while STAT displays the status of files or file systems. Learn how to use these commands with corresponding syntax and programming examples. The example program demonstrates the implementation of CHOWN and STAT in C, showcasing how to manage file ownership and retrieve file status effectively. Understand the structure and error handling for a robust Linux programming experience.
E N D
Linux Programming Example: 3 - 7 컴퓨터공학 2007242158 펠네르 파울로
Linux Programming • Contents • - CHOWN – How to use ( Method ) • STAT – How to use ( Method ) • Example: 3 - 7 Explanation
CHOWN Definition: Chown is a command for system that changes(변경)the owner(소유자)or group(그룹)of a file. Systax Chown [-R ] new-owner filenames
STAT • Definition: • Stat display file or file system status. • Syntax: • Stat [ option ] file…
Programming explanation #include <sys/types.h> #include <sys/stat.h> main(argc,argv) intargc; char *argv[]; { struct stat stbuf; int stat(), chown(); if(argc < 3) { printf("Usage: %s other-file your-file\n",argv[0]); exit(1); } if(stat(argv[1], &stbuf) == -1) { perror(argv[2]); exit(2); } if(chown(argv[2], stbuf.st_uid, stbuf.st_gid) == -1) { perror(argv[2]); exit(3); } exit(0); } Display file or system status Command for system that changes the owner of a file Print a system error message User ID of owner Group ID of owner