Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do you find the inode number of the name of files that start with a particular keyword like "test"?

We'll assume that there are files called: test, test1, test2.

share|improve this question
add comment

2 Answers

Try doing this (requires cygwin or such):

find . -type f -name 'test*' -printf '%p %i\n'

See

man find | less +/'-printf format'

Notes :

  • %p stands for file path
  • %i stands for inode number
share|improve this answer
    
+1 for not parsing ls output –  Michael Kjörling Jan 31 '13 at 15:02
add comment

There are a couple of ways to do this with find.

find . -iname 'test*' -type f -exec ls -i {} \;

find : the find command
. : the directory to search
-iname 'test*' : search for anything that matches test* regardless of case
-type f : only look for files
-exec ls -i {} \; : execute ls -i on each file found

find . -iname 'test*' -type f -printf '%i %f\n'

find : the find command
. : the directory to search
-iname 'test*' : search for anything that matches test* regardless of case
-type f : only look for files
-printf '%i %f\n' - print the inode, then the file's name only (no directories), and separate each file by a newline

Notes:

  • Substitute -iname for -name if you want to be case sensitive.
  • Substitute . with the absolute path if you want to search anything other than the current working directory.
  • Substitute %f with %p for the file's name, including the path (differs whether you use relative or absolute paths in your find command).
  • If you would like to be selective in your directories, don't forget the parameters -prune and -depth
  • You can be more specific with your string and do something like 'test[0-9]' to find everything test0-test9, or 'test[0-9]*' for anything with the string "test", then one digit, anything after that.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.