0

To clarify, this was in a windows system running wsl. The commands were run in windows cmd.exe.

So I was working in command prompt, doing some actions with git and switching between cmd.exe and wsl bash. Afterwards, I wanted to move a script file named "sh" to the home directory of my wsl2 ubuntu distribution.

So without thinking (In command prompt, not bash), I ran this exact command

mv sh ~sh

I realize now that I made two errors.

  1. Since I was not in bash, ~/ is not a valid path
  2. Even if I was in bash, I forgot the / in between ~ and sh

Essentially, my question is where did my file go?

But also Why didn't the command just rename the file sh to ~sh?

I already ran ls -a and dir in the directory in both command prompt and wsl bash. The file wasn't just named to ~sh and left in the directory as far as I can tell. Also for good measure, I searched my ubuntu home folder, but the file is nowhere to be found.

The script wasn't really important, but more I'm curious where it could have gone.

Doing some further digging, Running: where mv

Returns: C:\Program Files (x86)\WinAVR-20100110\utils\bin\mv.exe This leads me to believe that I didn't run the classic linux mv command but mv --help just describes essentially the bash mv command "Rename SOURCE to Dest...".

The only section that might be relevant is:

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:

But that doesn't really seem to apply to this usage.

I have looked for if the file is simply hidden and also turned off "hide system protected files" for the folder.

Edit (Copied from comment):

Running:

mv -i -v example.txt ~sh/example.txt

Returns:

mv: cannot move `example.txt' to `~sh/example.txt'

Running:

mv -i -v example.txt ~sh

Returns:

example.txt' -> `/example.txt'
8
  • For Linux /example.txt implies a move to the root of the filesystem, I'd check if the files are in `C:`
    – Hannu
    Aug 25, 2020 at 8:45
  • That's what I thought of too. But, there it is not there (I checked for hidden/system protected files there also). Aug 28, 2020 at 9:55
  • Hmm... wsl; at the bash prompt do cd / && ls -l and press enter.
    – Hannu
    Aug 28, 2020 at 17:55
  • Yeah, that just lists the C or wsl root depending on whether I run it in wsl or windows. I have already checked those places. Aug 31, 2020 at 17:23
  • sudo apt update && sudo apt install mlocate - please use your own judgment whether you need the mlocate package. Then do sudo updatedb && locate -i example.txt
    – Hannu
    Aug 31, 2020 at 21:55

1 Answer 1

0

In addition to ~ meaning your own home directory, bash and other Linux shells also support ~someuser to refer to that user's home directory.

And although you didn't run mv within bash, most such "Linux-utils-on-Windows" ports automatically invoke a compatibility layer which handles shell-like command line processing for them. (They already need it for wildcards/globs.)

So whatever version of mv you invoked thinks that there is a system user named "sh" (according to its /etc/passwd file), and has moved the file into that user's homedir.

Try mv -v -i someotherfile ~sh/test to hopefully convince it to reveal the full path that it uses.

1
  • So, I ran mv -v -i example.txt ~sh/example.txt in an administrator mode cmd.exe. The return was: example.txt' -> ~sh/example.txt'. mv: cannot move example.txt' to ~sh/example.txt' So I then ran mv -v -i example.txt ~sh and the return was example.txt' -> /example.txt'. Based on that, I double checked the root directory of my ubuntu wsl distro, but there was nothing there. I also checked C: . Currently I am running a search of my C drive for example.txt, but as you might imagine that'll take a while. Aug 24, 2020 at 20:15

You must log in to answer this question.

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