tags:

views:

62

answers:

3

I want to programatically read the contents of the /etc directory. If possible please reply with the code to achieve this.

+1  A: 

This is a simple application of opendir() and readdir() functions in C/C++ or their equivalents in Python, Perl or PHP. You will be able to see only files you have access to. It would help if you could explain what you want to accomplish.

Jim Garrison
+1  A: 

/etc directory is a usual directory. Work with it as you usually do with any other one.

FractalizeR
The contents of this directory is not usual. It contains the configuration parameters in it, what about those parameters
Sachin Chourasiya
Yet it is a usual directory in spite of what it contains. And it can be read and written just as any other one. Only permissions matter.
FractalizeR
A: 

The files in /etc are just ordinary files - you read them as you would any other files.

Understanding them on the other hand is more difficult - each file can have its own syntax, let alone attaching any meaning to the options within.

There is no special API for accessing the files in /etc.

Douglas Leeder