For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > July 2006 > How can i read the i-node of a directory?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How can i read the i-node of a directory?
babis85@gmail.com

2006-07-28, 4:00 am

Hello all,
i am reading the book of Kernighan "Programming in the Unix
Environment" and i found an example in which the od command was used
with parameters "-d .", thus "od -d .". I tried it in my system and it
doesn't work, while my man page for this command says that the
parameter have to be a file and not a directory. It was supposed that
this command would show me the contents of the current directory's
i-node. Have you any idea of how could i get that information?

Thanks a lot.

Pascal Bourguignon

2006-07-28, 4:00 am

babis85@gmail.com writes:
> i am reading the book of Kernighan "Programming in the Unix
> Environment" and i found an example in which the od command was used
> with parameters "-d .", thus "od -d .". I tried it in my system and it
> doesn't work, while my man page for this command says that the
> parameter have to be a file and not a directory. It was supposed that
> this command would show me the contents of the current directory's
> i-node. Have you any idea of how could i get that information?


On some recent unix systems, like Linux, directories can't be read as files.
You can use stat(1) to know the device and inode.

$ stat .
File: `.'
Size: 102400 Blocks: 208 IO Block: 4096 directory
Device: 303h/771d Inode: 947261 Links: 35
Access: (1777/drwxrwxrwt) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2005-03-14 16:29:31.000000000 +0100
Modify: 2006-07-28 11:30:00.000000000 +0200
Change: 2006-07-28 11:30:00.000000000 +0200

--
__Pascal Bourguignon__ http://www.informatimago.com/

The world will now reboot. don't bother saving your artefacts.
Daniel Rock

2006-07-28, 8:00 am

babis85@gmail.com wrote:
> It was supposed that
> this command would show me the contents of the current directory's
> i-node. Have you any idea of how could i get that information?


If you just want the inode number of the directory:

ls -id <dir>

If you want to read the contents of this directory - yes, that is also the
"ls" command.

--
Daniel
babis85@gmail.com

2006-07-28, 8:00 am


Pascal Bourguignon wrote:
> $ stat .
> File: `.'
> Size: 102400 Blocks: 208 IO Block: 4096 directory
> Device: 303h/771d Inode: 947261 Links: 35
> Access: (1777/drwxrwxrwt) Uid: ( 0/ root) Gid: ( 0/ root)
> Access: 2005-03-14 16:29:31.000000000 +0100
> Modify: 2006-07-28 11:30:00.000000000 +0200
> Change: 2006-07-28 11:30:00.000000000 +0200
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
>
> The world will now reboot. don't bother saving your artefacts.


Thanks, that was a good alternative. Actually, i wanted to see the
correspondence of a directory inode in terms of "inode number -
filename", where the filename is under the directory i choose as a
parameter. In that example there was this kind of view. Do you know how
could i do this?

Pascal Bourguignon

2006-07-28, 7:00 pm

babis85@gmail.com writes:

> Pascal Bourguignon wrote:
>
> Thanks, that was a good alternative. Actually, i wanted to see the
> correspondence of a directory inode in terms of "inode number -
> filename", where the filename is under the directory i choose as a
> parameter. In that example there was this kind of view. Do you know how
> could i do this?


As Daniel indicated, ls -li

--
__Pascal Bourguignon__ http://www.informatimago.com/

"A TRUE Klingon warrior does not comment his code!"
Logan Shaw

2006-07-28, 7:00 pm

Pascal Bourguignon wrote:
> babis85@gmail.com writes:
>
> As Daniel indicated, ls -li


"ls -1i" (note that one digit rather than the ell letter) has a
much more readable output, I think.

- Logan
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com