0

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.

3
  • 2
    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, 2012 at 3:46
  • i created using cp food1 ../food
    – apis17
    Jan 16, 2012 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, 2012 at 3:50

2 Answers 2

1

You could try something like this:

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

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
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .