How can I extract only the inode number for a file in Linux?

just a quick question. I want to use my inode number in a bash script, but I need help.

I use the ls -i "filename" , which echoes the "inode number" "filename". The problem is that I only need the inode number. Is there a way when I can "cut off" the output?

+5
source share
2 answers

You can use the stat command with %i to get only inode nuymbers:

 stat -c '%i' * 

Most utilities / commands use the lstat system call, which is used by the stat command, to use the inode.

+5
source

you can also awk over ls

  -bash-3.2$ ls -i current.py | awk '{print $1}' 
+1
source

All Articles