Accidentally moved home folder?

Solution 1:

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 ~.

Solution 2:

The tilde is expanded by the shell to the $HOME of the user, in your case /home/liso. In the first command you escaped the ~ so it was not expanded to the location you wanted, instead it was passed literally to mv as the symbol ~.

I think you wanted to run

mv sublime.desktop ~/.local/share/applications

(with an optional trailing /)

I would expect the command you say you ran to fail like this

mv: cannot move 'sublime.desktop' to '~/.local/share/applications/': No such file or directory

because mv does not create destination directories like that. If you really did run that command, I think you must have already had a directory actually named ~ in your Desktop with that path, ie

/home/liso/Desktop/\~/.local/share/applications

and if so you will now find a file there:

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

And you should run

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

But if you ran

mv sublime.desktop \~

that would create a file ~ because sublime.desktop would be renamed ~. Try reading the file

less ~Desktop/\~

If it contains the contents of your sublime.desktop file, then run

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

Solution 3:

The tilde character is only expanded to your home directory (among other possibilities) when it is not quoted. Putting a \ character in front of it prevents tilde expansion. When in doubt, use $HOME instead, as it is a regular shell variable with a predictable syntax and behavior.

To remove a directory named ~ (make sure there's nothing of importance in it first), you should use the same trick as before: escape the tilde so it's interpreted literally. Oh, and you'll also need to run rm recursively to remove a non-empty directory:

rm -r "~"