Rename a file based on inode

To rename file or directory in Linux using the inode number, we need to know their inode number. Use the ' ls -i ' to find out the inode number for the files or directory.

 

[root@fedora ~]# ls -i

648389 anaconda-ks.cfg 97315 example-directory 1847716 install.log.syslog

97582 Desktop 1847715 install-fedora.log 648395 X.txt

 

Now let use the example-directory with inode number 97315 as an experiment for the example.

Now, execute the find command to find the example-directory inode number than rename that directory to new-directory-name.

 

[root@fedora ~]# find . -inum 97315 -exec mv {} new-directory-name \;

find: ./example-directory: No such file or directory

 

To verify the change on the directory name, use the ls command with the ' -i ' option to list file and folder including their inode number.

 

[root@fedora ~]# ls -i

648389 anaconda-ks.cfg 1847715 install-fedora.log 97315 new-directory-name

97582 Desktop 1847716 install.log.syslog 648395 X.txt

 

Command explanations:

 

• The 'ls -i' command is usually to get the inode number for file and directory in Linux or Unix system:

 

ls -i

 

• This line of command use 'find' command to find the inode number given than execute the 'mv' command to rename the file or directory:

 

find . -inum 97315 -exec mv {} new-directory-name \;

 

• To verify the changes to the filename 'ls -i' is use again:

 

ls -i

 

The above information was extracted from http://www.labtestproject.com/linuxcmd/mv.html