I have a file named 123 and one main folder also named 123 which contains a subfolder of the same name.

How can I move file 123 into the folder 123 since both the file and main folder have the same name in terminal?


This can be achieved by moving the file from another directory into the folder that is named the same.

i have wrote a simple example of how you can do this below.

cd ~
mkdir test
nano 123
cd test
mkdir 123
cd ~ 
mv 123 test/123
| improve this answer | |
  • If you wouldnt mind selected an answer that would be great. – IndieBlock Jan 25 '16 at 11:03

It's not possible to have a file and a folder by the same name. If you analyze the name close enough you will notice the names are not the same.

In Linux the files are case different. I'm sure you used 123 as an example just to specify both have the same file name as in abc. The name can consist of alphabets or numbers. The name can even be spaces or as well as a combination of many symbols. Also the file/directory names are case sensitive.

Files with alphabet names, being case sensitive, means, the following file names are different. You can have a directory of file by the following abc combination:

abc aBc aBC

You can also place a space or a number of spaces anywhere around from the front of all the letters to the end of all the letters as well as in between any of the letters. That would make the directory name different, even though it would have all the same letters and resemble the same.

You can see the details of the names and which ones are folders and which are files with this command:

$ ls -la

In that command the l is specifying give the long output which will show you more details about the item. Looking at it this way you will have a d at the far left of the details to specify the item is a folder (a directory). You'll also see the actual item names in a list that will make it easier for you to see the differences. There will be differences unless your system is corrupted if which you might need to run a command such as fsck to fix.

You might consider adding the content of the ls command to your question so that the problem are experiencing would be clearer.

You can get to the terminal to execute the ls command by hitting AltCntrlT

You can move the file to a directory by that name with the same way you would move any file. Type in the full pathname of the filename and the full pathname of the directory name.

This is an example:
(The third line shows the move command of the file with the same name.)

$ mkdir /tmp/test
$ mkdir /tmp/test/123
$ echo hello > /tmp/123
$ mv /tmp/123 /tmp/test/123
$ nautilus /tmp/test

If you typed the commands above in a terminal window the last command will bring up a window of the test directory in your /tmp/ folder. It'll have one directory by the name of 123 with a file in it by the same name.

| improve this answer | |

Try this. But you can do it like as usual.

mv /path_to_source_folder/123.txt /123/single/

Here the first one is the path and it's filename name with extension than we used the main foldername123 and followed by your folder single I guess this will do the things.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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