how to find file? - Linux

This is a discussion on how to find file? - Linux ; hi i have inode number of file. but i want to know that can i found file name by using inode number. chandrakant solanki...

+ Reply to Thread
Results 1 to 9 of 9

Thread: how to find file?

  1. how to find file?

    hi

    i have inode number of file.
    but i want to know that can i found file name by using inode number.

    chandrakant solanki


  2. Re: how to find file?

    solanki.chandrakant@gmail.com wrote:
    > hi
    >
    > i have inode number of file.
    > but i want to know that can i found file name by using inode number.


    find -xdev -inum

    e.g.
    find / -xdev -inum 10

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett


  3. Re: how to find file?


    hi

    thanks for reply but the command you''ve given me is not work.

    And the second thing is to i want to do the same with the help of c
    programming... is it possible ? if yes, then how ..?

    Chandrakant


  4. Re: how to find file?

    solanki.chandrakant@gmail.com wrote:
    > hi
    >
    > thanks for reply but the command you''ve given me is not work.


    Why not?
    Are you sure the file with the given i-number does exist?

    # ls -lisa /etc/mgetty+sendfax/login.config
    76 [...] /etc/mgetty+sendfax/login.config
    # find / -xdev -inum 76
    /etc/mgetty+sendfax/login.config

    > And the second thing is to i want to do the same with the help of c
    > programming... is it possible ? if yes, then how ..?


    A combination of ftw() and stat() would do the trick.
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett


  5. Re: how to find file?

    hi

    can i know that whether the inode number is in hex number or it should
    be an integer number..
    b'coz i have searched for that but it not works...

    i have insert my code over here if any mistake then plz suggest me...
    in the following code i have to find the file name for inode number
    6216.


    #include

    #include
    #include
    #include
    #include
    #include

    #include

    int main( void )
    {
    DIR *dir;

    char path[128] = "";
    struct stat s;
    struct dirent *entry;

    int iFD = 0;

    char *dPath[24] = { "/usr/bin/" };

    int i = 0;
    for( i = 0; i < 1; i++ )
    {
    dir = opendir( dPath[i] );

    if( !dir ) {
    fprintf( stderr,"error: unable to open dir\n"
    );
    return 0;
    }
    else
    {
    while( ( entry = readdir( dir ) ) )
    {
    if( entry->d_type == DT_DIR )
    continue;

    strcpy( path, dPath[i] );
    strcat( path, entry->d_name );

    iFD = open( path, O_RDONLY );
    if( fstat( iFD, &s ) != -1 )
    {
    if( s.st_ino == 6216 )
    printf( "%d\t%s\n",
    s.st_ino, entry->d_name );
    }
    else
    ;
    close( iFD );
    }
    closedir( dir );
    }
    }
    return 0;
    }


  6. Re: how to find file?

    solanki.chandrakant@gmail.com wrote:
    > hi
    >
    > can i know that whether the inode number is in hex number or it should
    > be an integer number..


    ??? a number is a number is a number

    Whether it's hex or decimal or octal or binary or a couple of lumps of
    electrons is just a matter of representation!

    > b'coz i have searched for that but it not works...


    Please refrain from kiddie talk. It's "Because" ...

    > i have insert my code over here if any mistake then plz suggest me...


    ... and "please".

    > in the following code i have to find the file name for inode number
    > 6216.


    Are you sure it exists at all in /usr/bin? Maybe it is in /usr/sbin or
    in /usr/lib or ...
    What happens if you do "ls -i /usr/bin | fgrep 6216" Does it show any
    file with i-number 6216?

    Code deleted, sorry, I have no time checking your code and finding bugs
    in it. But ... what's so bad about using ftw?
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett


  7. Re: how to find file?

    In article ,
    Josef Moellers wrote:

    >Are you sure the file with the given i-number does exist?


    And does it have a directory entry somewhere?

    --
    http://www.spinics.net/lists/

  8. Re: how to find file?

    On 20 Dec 2006 01:59:51 -0800 solanki.chandrakant@gmail.com wrote:

    | hi
    |
    | thanks for reply but the command you''ve given me is not work.
    |
    | And the second thing is to i want to do the same with the help of c
    | programming... is it possible ? if yes, then how ..?
    |
    | Chandrakant

    It is also possible the file becomes unlinked to link count zero
    somewhere between when you get its inode and when you would have
    found a link to it othewise. Even if the file is still open and
    exists without a name, this can happen.

    Also, the inode is not enough if there is more than one filesystem
    mounted. With 2 or more filesystems, each can have a file of the
    very same inode number. The distinction is the device number of
    the filesystem. A combination of the filesystem device number and
    the inode number would uniquely identify a file on a machine if it
    still exists.

  9. Re: how to find file?

    First, your program has a logic error (just one character) before
    statement
    close( iFD );

    ^_^


    solanki.chandrakant@gmail.com wrote:
    > hi
    >
    > can i know that whether the inode number is in hex number or it should
    > be an integer number..
    > b'coz i have searched for that but it not works...
    >
    > i have insert my code over here if any mistake then plz suggest me...
    > in the following code i have to find the file name for inode number
    > 6216.
    >
    >
    > #include
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > #include
    >
    > int main( void )
    > {
    > DIR *dir;
    >
    > char path[128] = "";
    > struct stat s;
    > struct dirent *entry;
    >
    > int iFD = 0;
    >
    > char *dPath[24] = { "/usr/bin/" };
    >
    > int i = 0;
    > for( i = 0; i < 1; i++ )
    > {
    > dir = opendir( dPath[i] );
    >
    > if( !dir ) {
    > fprintf( stderr,"error: unable to open dir\n"
    > );
    > return 0;
    > }
    > else
    > {
    > while( ( entry = readdir( dir ) ) )
    > {
    > if( entry->d_type == DT_DIR )
    > continue;
    >
    > strcpy( path, dPath[i] );
    > strcat( path, entry->d_name );
    >
    > iFD = open( path, O_RDONLY );
    > if( fstat( iFD, &s ) != -1 )
    > {
    > if( s.st_ino == 6216 )
    > printf( "%d\t%s\n",
    > s.st_ino, entry->d_name );
    > }
    > else
    > ;
    > close( iFD );
    > }
    > closedir( dir );
    > }
    > }
    > return 0;
    > }



+ Reply to Thread