How to find inode number using "find" command?
Solution 1
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
Solution 2
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.
Related videos on Youtube
nullheart
Updated on September 18, 2022Comments
-
nullheart over 1 year
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.
-
user about 11 years+1 for not parsing
ls
output -
Hallaghan about 7 yearsWhen using a BSD system, GNU
find
must be installed. E.g. in FreeBSDpkg install findutils
then usegfind
.