Bash on Windows: mv command - cannot move to a subdirectory of itself

5,328

Solution 1

Thanks for the responses everyone, but it turns out that this is a bug with the beta version of Bash on Windows.

One of the developers posted a comment to their issue tracker on 2016-04-11:

We have a fix internally on one of our dev branches. Should hit the insiders builds before too long.

Solution 2

Try without the trailing / on the source argument. With that there, you are telling the OS to move the contents of the directory but not specifying the files, and not the directory. That's actually a convention that many unix systems follow across commands.

So instead of: mv ~/ruby/ruby-2.3.0/ /opt/rubies/

try: mv ~/ruby/ruby-2.3.0 /opt/rubies/

You also need to make sure that you are not running the command with PWD = ~/ruby/ruby-2.3.0 because then you are trying to move the directory you are in. cd ~; mv ~/ruby/ruby-2.3.0 /opt/rubies/

Solution 3

Am I doing something wrong?

mv ~/ruby/ruby-2.3.0/ /opt/rubies/

You need to remove both trailing /s.

Does directory /opt/rubies/ruby-2.3.0 already exist? Check by running:

ls /opt/rubies/ruby-2.3.0

If it does exist run the following command to remove it:

rm -rf /opt/rubies/ruby-2.3.0

Now use the following command to do the move:

mv ~/ruby/ruby-2.3.0 /opt/rubies

This will create the directory /opt/rubies/ruby-2.3.0


Further Reading

Share:
5,328

Related videos on Youtube

Sly_cardinal
Author by

Sly_cardinal

Updated on September 18, 2022

Comments

  • Sly_cardinal
    Sly_cardinal over 1 year

    I'm trying to install Ruby from sources on the Windows Linux Subsystem. I've successfully built from source in my home directory: ~/ruby/ruby-2.3.0 and I'm trying to move it to /opt/rubies/.

    When I run the move command I get the following error:

    /# mv ~/ruby/ruby-2.3.0/ /opt/rubies/
    mv: cannot move ‘/root/ruby/ruby-2.3.0/’ to a subdirectory of itself, ‘/opt/rubies/ruby-2.3.0’
    

    This is super confusing as I'm moving the directory to a totally different location, not a subdirectory of itself, as the paths themselves show.

    It does the same thing for any move command under my home directory:

    ~# mv test/ /
    mv: cannot move ‘test/’ to a subdirectory of itself, ‘/test’
    

    And I can't seem to copy any files either:

    ~# cp ruby/ruby-2.3.0/ /opt/rubies/ruby-2.3.0
    cp: omitting directory ‘ruby/ruby-2.3.0/’
    

    Am I doing something wrong?

  • Sly_cardinal
    Sly_cardinal about 8 years
    I've tried all combinations of trailing slashes - with and without - and it still gives the same error. In the first example I was running the command from PWD = / so I wasn't inside the directory being moved.
  • Sly_cardinal
    Sly_cardinal about 8 years
    It fails both with and without the trailing slashes. I've confirmed that the destination directory is empty as well.