To Query the file attributes in unix using a c program

In summary, to query the file attributes in Unix using a C program, you can use the stat() function. This function returns a structure with information such as size, type, and permissions. Some common file attributes that can be queried include size, permissions, owner, group, and dates. To check if a file exists, use the access() function. It is possible to query the attributes of multiple files at once using a loop and the stat() function. You can also change file attributes using the chmod() and chown() functions, but appropriate permissions are required.
  • #1
Naveenchandra
3
0
Hello guys,
I am trying to query the file attributes in unix using a c program..Little help please :)
 
Technology news on Phys.org
  • #3
Thanks for the help..:)
 

1. How can I query the file attributes in Unix using a C program?

To query the file attributes in Unix using a C program, you can use the stat() function. This function takes in the name of the file as a parameter and returns a structure containing information about the file, including its size, type, and permissions.

2. What are the different file attributes that can be queried in Unix?

Some of the common file attributes that can be queried in Unix include the file size, permissions, owner, group, creation/modification/access dates, and file type.

3. How do I check if a file exists using a C program in Unix?

You can use the access() function to check if a file exists in Unix using a C program. This function takes in the name of the file and a mode as parameters and returns 0 if the file exists or -1 if it does not.

4. Can I query the file attributes of multiple files at once in Unix?

Yes, it is possible to query the file attributes of multiple files at once in Unix using a C program. You can use the stat() function in a loop to get the attributes of each file and store them in an array or a data structure for further processing.

5. Is it possible to change the file attributes using a C program in Unix?

Yes, it is possible to change the file attributes using a C program in Unix. You can use the chmod() function to change the file permissions or the chown() function to change the owner and group of a file. However, you will need appropriate permissions to make these changes.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
3
Views
356
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
9
Views
565
  • Programming and Computer Science
Replies
2
Views
630
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
Replies
2
Views
347
  • Programming and Computer Science
Replies
2
Views
276
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
22
Views
905
Back
Top