Напишите программу, осуществляющую выдачу информации об элементе каталога. Имя элемента программа получает из командной строки

Используемые библиотеки:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <time.h>

Используемые функции:

int stat( const char *filename, struct stat *buf); - следует по символьным ссылкам

ctime(time_t *datetime) - преобразует time_t в string

Поле: st_mtime /* время последнего изменения*/

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $ ./prog s1

Время последнего изменения Sun Dec 23 16:48:43 2012

 

Ответ:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

#include <time.h>

int main(int argc, char **argv)

{struct stat s;

stat(argv[1], &s);

fprintf(stdout,"Время последнего изменения %s\n",ctime(&s.st_mtime));}

Напишите программу, осуществляющую выдачу информации об элементе каталога. Имя элемента программа получает из командной строки.

Используемые библиотеки:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <time.h>

Используемые функции:

int lstat( const char *filename, struct stat *buf); -не следует по символьным ссылкам

ctime(time_t *datetime) - преобразует time_t в string

Поле: st_mtime /* время последнего изменения*/

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $ ./prog s1

Время последнего изменения Sun Dec 23 17:22:05 2012

Ответ:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

#include <time.h>

int main(int argc, char **argv)

{ struct stat lst;

lstat(argv[1], &lst);

fprintf(stdout,"Время последнего изменения %s\n",ctime(&lst.st_mtime));}

Напишите программу, осуществляющую выдачу информации об элементе каталога. Имя элемента программа получает из командной строки.

Используемые библиотеки:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <time.h>

Используемые функции:

int stat( const char *filename, struct stat *buf); - следует по символьным ссылкам

ctime(time_t *datetime) - преобразует time_t в string

Поле: st_mtime /* время последнего изменения*/

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $ ./prog s3

Время последнего изменения Sun Dec 23 17:20:15 2012

 

Ответ:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

#include <time.h>

int main(int argc, char **argv)

{struct stat s;

stat(argv[1], &s);

fprintf(stdout,"Время последнего изменения %s\n",ctime(&s.st_mtime));}

Напишите программу, осуществляющую выдачу информации об элементе каталога. Имя элемента программа получает из командной строки.

Используемые библиотеки:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <time.h>

Используемые функции:

int lstat( const char *filename, struct stat *buf); -не следует по символьным ссылкам

ctime(time_t *datetime) - преобразует time_t в string

Поле: st_mtime /* время последнего изменения*/

student@loony ~/new $ ls -lF

-rwx------ 3 student student 187 2012-12-23 17:20 1.c*

drwxrwxr-x 2 student student 4096 2012-12-23 16:48 p1/

-rwxrwxr-x 1 student student 8623 2012-12-23 20:29 prog*

lrwxrwxrwx 1 student student 2 2012-12-23 17:22 s1 -> p1/

lrwxrwxrwx 1 student student 3 2012-12-23 17:24 s3 -> 1.c*

student@loony ~/new $ ./prog s3

Время последнего изменения Sun Dec 23 17:24:43 2012

Ответ:

#include <sys/types.h>

#include <sys/stat.h>

#include <unistd.h>

#include <stdio.h>

#include <time.h>

int main(int argc, char **argv)

{ struct stat lst;

lstat(argv[1], &lst);

fprintf(stdout,"Время последнего изменения %s\n",ctime(&lst.st_mtime));}