Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

how to move file with same name as folder

for example:

#ls
total 2
.
..
-rwxr-xr-x  1 root     root      230 Jan 16 10:39   food <file to move>
drwx--x--x 12 root     root     4096 Jan 16 11:25   food <directory>

i want to move food into food directory.

final output should be food/food.ini

when i use #mv food food/food.ini there an error

mv: cannot move `food' to a subdirectory of itself, `food/food.ini'

update:

this file created using following commands:

cp foods1 ../food

where food folder is available at parent directory.

i can move using webmin. but the file not exists when trying to edit using vi editor.

share|improve this question
1  
Is this a real problem or a theoretical situation? If a real problem, how did this happen? Linux will typically not permit you to create a file and directory with the same name inside the same parent directory. –  EEAA Jan 16 '12 at 3:46
    
i created using cp food1 ../food –  apis17 Jan 16 '12 at 3:49
    
i can move using webmin. but not sure to move that file using command line. if possible how webmin can move for me? –  apis17 Jan 16 '12 at 3:50

2 Answers 2

up vote 1 down vote accepted

You could try something like this:

find ./ -name food -type f -exec mv {} ./food/{} \;
share|improve this answer
    
i already deleted the file and cannot reproduce the problem. this is acceptable answer. thank you. –  apis17 Jan 16 '12 at 4:41

I cannot duplicate the method you used to create a file and a directory with the same name in the same folder, but you can clean up the situation by moving the file using its inode number rather than its name through something like the find command.

[jpaulus@localhost test]$ ls -lhi
total 4.0K
26086760 drwxrwxr-x 2 jpaulus jpaulus 4.0K Jan 15 23:19 test
26086768 -rw-rw-r-- 1 jpaulus jpaulus    0 Jan 15 23:19 test1

find . -inum 26086760 -exec mv {} new_directory/new_filename \;

[jpaulus@localhost test]$ ls -lh
total 0
-rw-rw-r-- 1 jpaulus jpaulus 0 Jan 15 23:19 test1
share|improve this answer
    
thanks for -lhi command. can i move file using inode number? –  apis17 Jan 16 '12 at 4:31
    
ok its can: labtestproject.com/linuxcmd/mv.html –  apis17 Jan 16 '12 at 4:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.