Ubuntu – Accidentally moved home folder

command linemv

I'm not quite sure what just happened, all I did was running:

~/Desktop$ mv sublime.desktop \~/.local/share/applications/

The \ sign before ~/.local came up as autocomplete, so I thought it was okay to run it.

But instead of moving the desktop file to /.local/share/applications/ (which was my intention), the command created new folder on Desktop. (The ~ was folder)

Liso@thinkpad:~/Desktop$ ls
~  backup.sql  Apps

When I tried to remove ~:

~/Desktop$ rmdir ~
rmdir: failed to remove ‘/home/liso’: Permission denied

So what am I missing actually ?

EDIT

@Ravexina ask me to ran test command to confirm whether it was a directory or a file.

Liso@thinkpad:~/Desktop$ test -d \~ && echo "it's a dir"
it's a dir`

Best Answer

You didn't move your home directory...

  • We refer to ~ as tilde expansion, most of the times it will be replaced with the value of the $HOME shell variable, before the command get executed.

  • \ is the strongest type of quoting in the shell.

So using \~ you are skipping the tilde expansion by quoting it. Means that you are actually saying: move the "sublime.desktop" to a new file named exactly "~...".

I can't reproduce your command's result, but somehow you ended up with a file/directory exactly named ~.

Check to see if it's a file or directory and get a list of its contents:

test -d ~/Desktop/~ && ls -l ~/Desktop/~ || echo 'it is a file'

Then move them to the correct path, if it was a file to move it back you have to escape its name again, otherwise it will be expanded to /home/liso:

mv \~ new-name
mv "~" new-name # works
mv '~' new-name # also works
mv ~/Desktop/~  new-name # works fine too

And remember by rmdir ~ you are trying to remove the actual home directory: /home/liso not the ~.

Related Question