Tuesday, 14 May 2013

Two files with same name in a directory !!!


Have you ever seen two files with same name inside a directory ? Is it possible at all ? What if a user shows you this, right in front of your eyes ?

Actually, it is impossible to have two files of the same name in a directory,unix does not permit this. If at all such behaviour is observed, then one of the files must have control characters in its name!! and it simply means these are 2 different files and so must have different inode numbers.

Check the different inode numbers of the files with below command.

# ls -lib           -----> this command will show inode number and any control characters in the filename.

The man page for ls says that –b will ……
List nonprinting characters in the octal \ddd notation


Once we have the inode number ( in the example below i am using 2460 as inode number), we can easily use find command to move the dubious file to a safe location and delete it there.

# find / -xdev -inum 2460 -exec mv {} /tmp/wastebin/ \;
# rm –rf /tmp/wastebin

No comments:

Post a Comment