Write a program in Python/C++ to read display the i-node information for a given text file, image file
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
char fd[20];
struct stat *buf;
buf=new struct stat;
cout<<"Enter name of the file";
cin>>fd;
stat(fd,buf);
cout<<"\n **INFO**";
cout<<"\n The size of file is"<<buf->st_size;
cout<<"\n Inode number is"<<buf->st_ino;
cout<<"\n ID of device"<<buf->st_dev;
cout<<"\nFile permission";
cout<<((S_ISDIR(buf->st_mode))?"d":"-");
cout<<((buf->st_mode & S_IRUSR)?"r":"-");
cout<<((buf->st_mode & S_IWUSR)?"w":"-");
cout<<((buf->st_mode & S_IXUSR)?"x":"-");
cout<<((buf->st_mode & S_IRGRP)?"r":"-");
cout<<((buf->st_mode & S_IWGRP)?"W":"-");
cout<<((buf->st_mode & S_IXGRP)?"x":"-");
cout<<((buf->st_mode & S_IROTH)?"r":"-");
cout<<((buf->st_mode & S_IWOTH)?"w":"-");
cout<<((buf->st_mode & S_IXOTH)?"x":"-");
cout<<"\n Number of hardlinks"<<buf->st_nlink;
cout<<"\n User id"<<buf->st_uid;
cout<<"\n Group id"<<buf->st_gid;
cout<<"\nDevic ID"<<buf->st_rdev;
cout<<"\nBlocks"<<buf->st_blocks;
cout<<"\nLast access time"<<ctime(&(buf->st_atime));
cout<<"\nLast modification time"<<ctime(&(buf->st_mtime));
cout<<"\nLast status change time"<<ctime(&(buf->st_ctime));
free(buf);
return 0;
}
/****************OUTPUT***********************
[soetcomp@localhost ~]$ gedit a[4].cpp
[soetcomp@localhost ~]$ g++ a[4].cpp
[soetcomp@localhost ~]$ ./a.out
Enter name of the file5.cpp
**INFO**
The size of file is225
Inode number is796927
ID of device64769
File permission-rw-rW-r--
Number of hardlinks1
User id1000
Group id1000
Devic ID0
Blocks8
Last access timeWed Aug 19 08:28:20 2015
Last modification timeWed Aug 19 08:28:12 2015
Last status change timeWed Aug 19 08:28:12 2015*/
#include<sys/stat.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
char fd[20];
struct stat *buf;
buf=new struct stat;
cout<<"Enter name of the file";
cin>>fd;
stat(fd,buf);
cout<<"\n **INFO**";
cout<<"\n The size of file is"<<buf->st_size;
cout<<"\n Inode number is"<<buf->st_ino;
cout<<"\n ID of device"<<buf->st_dev;
cout<<"\nFile permission";
cout<<((S_ISDIR(buf->st_mode))?"d":"-");
cout<<((buf->st_mode & S_IRUSR)?"r":"-");
cout<<((buf->st_mode & S_IWUSR)?"w":"-");
cout<<((buf->st_mode & S_IXUSR)?"x":"-");
cout<<((buf->st_mode & S_IRGRP)?"r":"-");
cout<<((buf->st_mode & S_IWGRP)?"W":"-");
cout<<((buf->st_mode & S_IXGRP)?"x":"-");
cout<<((buf->st_mode & S_IROTH)?"r":"-");
cout<<((buf->st_mode & S_IWOTH)?"w":"-");
cout<<((buf->st_mode & S_IXOTH)?"x":"-");
cout<<"\n Number of hardlinks"<<buf->st_nlink;
cout<<"\n User id"<<buf->st_uid;
cout<<"\n Group id"<<buf->st_gid;
cout<<"\nDevic ID"<<buf->st_rdev;
cout<<"\nBlocks"<<buf->st_blocks;
cout<<"\nLast access time"<<ctime(&(buf->st_atime));
cout<<"\nLast modification time"<<ctime(&(buf->st_mtime));
cout<<"\nLast status change time"<<ctime(&(buf->st_ctime));
free(buf);
return 0;
}
/****************OUTPUT***********************
[soetcomp@localhost ~]$ gedit a[4].cpp
[soetcomp@localhost ~]$ g++ a[4].cpp
[soetcomp@localhost ~]$ ./a.out
Enter name of the file5.cpp
**INFO**
The size of file is225
Inode number is796927
ID of device64769
File permission-rw-rW-r--
Number of hardlinks1
User id1000
Group id1000
Devic ID0
Blocks8
Last access timeWed Aug 19 08:28:20 2015
Last modification timeWed Aug 19 08:28:12 2015
Last status change timeWed Aug 19 08:28:12 2015*/
Comments
Post a Comment