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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityTry 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 numberfind
must be installed. E.g. in FreeBSD pkg install findutils
then use gfind
.
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:
-iname
for -name
if you want to be case sensitive..
with the absolute path if you want to search anything other than the current working directory. %f
with %p
for the file's name, including the path (differs whether you use relative or absolute paths in your find command).-prune
and -depth
'test[0-9]'
to find everything test0-test9, or 'test[0-9]*'
for anything with the string "test", then one digit, anything after that.