Tuesday, 23 April 2013

Unix: Access a file using its Inode Number


Lets suppose you have downloaded a file on your unix system which has some name that cannot be used with unix commands. For example, name of the file is "-ROOT- " . Now if you try to  copy , delete or rename this file 

 mv  -ROOT-  ROOT

you will get error saying something like invalid option -R .
You can access this file using its inode number which can you get by running "ls -i " in the directory that contains the file.
Lets suppose inode number of  -ROOT- is 15487
so you can perform above operations as

find . -inum 15487 -exec mv {} ROOT \;

Also, while you can delete this file as follows

find . -inum 15487 -exec rm {} \;

No comments:

Post a Comment