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.

There is literally nothing on google that I can find that will help me answer this question. I presume it is passing some other parameter to ls -i?

share|improve this question

2 Answers 2

up vote 12 down vote accepted

Yes, the argument -i will print the inode number of each file or directory the ls command is listing. As you want to print the inode number of a directory, I would suggest using the argument -d to only list directories. For just printing the inode number of your home directory, use the following command line:

ls -id ~

From man ls:

   -d, --directory
          list  directory entries instead of contents, and do not derefer‐
          ence symbolic links
   -i, --inode
          print the index number of each file
share|improve this answer

This works also with stat:

DIR=/
stat -c '%i' $DIR

From man stat:

   -c  --format=FORMAT
          use the specified FORMAT instead of the default; output  a  new‐
          line after each use of FORMAT
[...]

   The valid format sequences for files:    
       %i     inode number
share|improve this answer
    
Thank you. Always good to have more than one solution. –  Strobe_ Mar 27 at 19:17
    
I'd like to add that the stat command from FreeBSD, NetBSD, OpenBSD and OS X works a bit differently and stat -f '%i' $DIR has to be used. –  Cristian Ciupitu Jun 24 at 23:02

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.