0

I technically know how to do all these things, but combining it is problematic. Inode is saved in first line of text file (I can eventually read it directly from file), I need results saved to the same file.

How can I do this?

2 Answers2

2

You can use find utility with -inum parameter. From man 1 find:

-inum n

File has inode number n. It is normally easier to use the

-samefile test instead.

  • I have tried "locate -inum ls -i /home/user/file | cat>file2" and it's giving me error "locate: invalid value 'um' of --limit". I have found that locate is used to find files in whole system. – Corporal Girrafe May 24 '19 at 16:24
  • @Corporal Girrafe Please, use find instead of locate. – Yurij Goncharuk May 24 '19 at 19:29
  • But won't find search only in folder where script is located? – Corporal Girrafe May 25 '19 at 17:44
  • I have came up with something like that - find -ls ln -i /home/user/folder/file | cat>>save but i get find: paths must precede expression ln error. And this is the issue, i don't have the path, i want to search in whole system. – Corporal Girrafe May 25 '19 at 19:45
1

You can use find command with the argument -inum with inode number like as below

Example-

touch /home/ajeet/original_file.txt
ln /home/ajeet/original_file.txt /root/hard_link_file.txt

ls -li /root/hard_link_file.txt
1704088 -rw-r--r-- 2 root root 0 May 24 18:24 /root/hard_link_file.txt

ls -li /home/ajeet/original_file.txt
1704088 -rw-r--r-- 2 root root 0 May 24 18:24 /home/ajeet/original_file.txt

find / -inum 1704088
/home/ajeet/original_file.txt
/root/hard_link_file.txt
Chris Davies
  • 116,213
  • 16
  • 160
  • 287