Skip to main content

How to Rename a File Using Its Inode on Debian

Below is a clean, step‑by‑step guide that shows how to locate a file’s inode and rename it (or copy it under a new name) without knowing the exact filename.


1️⃣ Go to the Directory Containing the Target File

cd /path/to/directory/

Tip: You can also run commands from any directory; just adjust the paths accordingly.


2️⃣ List Inodes of All Files in that Directory

ls -i

The output will look like:

1234567  file_to_rename.txt
2345678  another_file.docx
...

The number on the left (1234567 in this example) is the inode.


3️⃣ Rename (or Copy) the File Using Its Inode

Option A – Rename directly (no copy):

find . -inum 1234567 -type f -exec mv {} new_name.txt \;

Option B – Copy to a new name, then optionally delete the original:

# Copy only
find . -inum 1234567 -type f -exec cp {} new_name.txt \;

# (Optional) Remove the old file after copying
find . -inum 1234567 -type f -delete

Explanation

  • find . – search in the current directory.
  • -inum 1234567 – match the inode you identified.
  • -type f – ensure it’s a regular file.
  • -exec … \; – run the command (mv or cp) on each matched file.

✅ Verify the Result

ls -i new_name.txt

You should see that the inode matches the original (unless you copied to another filesystem, in which case it will be a new inode).


Quick Summary

Step Command
1 cd /path/to/directory/
2 ls -i
3a find . -inum <inode> -type f -exec mv {} new_name.txt \;
3b find . -inum <inode> -type f -exec cp {} new_name.txt \; (then delete if desired)

Feel free to copy this guide or adapt it for scripts, automation, or teaching purposes. Happy file‑manipulating!