Bash в Windows: команда mv - не может перейти в свой подкаталог

3045
Sly_cardinal

Я пытаюсь установить Ruby из источников в подсистеме Windows Linux. Я успешно собрал из исходного кода в своем домашнем каталоге: ~/ruby/ruby-2.3.0и я пытаюсь переместить его в /opt/rubies/.

Когда я запускаю команду перемещения, я получаю следующую ошибку:

/# 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’ 

Это очень запутанно, так как я перемещаю каталог в совершенно другое место, а не в сам подкаталог, как показывают сами пути.

Это делает то же самое для любой команды перемещения в моем домашнем каталоге:

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

И я не могу скопировать файлы либо:

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

Я делаю что-то неправильно?

1

3 ответа на вопрос

2
Sly_cardinal

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.

1
DavidPostill

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

Это терпит неудачу и с и без завершающих слешей. Я подтвердил, что каталог назначения также пуст. Sly_cardinal 8 лет назад 0
0
Rowan Hawkins

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/

Я перепробовал все комбинации конечных слешей - с и без - и все равно выдает ту же ошибку. В первом примере я выполнял команду из `PWD = /`, поэтому меня не было в перемещаемом каталоге. Sly_cardinal 8 лет назад 0