How these commands work depends on where you are in the filesystem.
You can normally see where you are from your prompt:
zanna@monster:~/Desktop$
That's my prompt when the current working directory is ~/Desktop
, the handy shortcut for /home/zanna/Desktop
If you're not sure where you are, you can type pwd
and get the full absolute path
zanna@monster:~/Desktop$ pwd
/home/zanna/Desktop
The first /
is important - that's the root directory, and all full absolute paths will start with it
You can use absolute or relative paths to do things with files. If you are in the directory where the file you want to move is, to move to your desktop, assuming your desktop directory is actually called Desktop
(don't forget that Linux is case sensitive)
mv file1 ~/Desktop
because the current working directory is assumed.
From anywhere in your filesystem you can do this:
mv /path/to/file1 ~/Desktop
but replace /path/to with the real path! for example, if the file is in you home Downloads folder do
mv ~/Downloads/file1 ~/Desktop
mv
also renames files... if the target is a file that exists and isn't a directory, mv
overwrites it with the contents of the first file, and renames to the target. If the file doesn't exist, then file1
is renamed as the target without overwriting anything, as you discovered.
To copy a file instead of moving it, you can do exactly the same as above, with cp
instead of mv
. Only the behaviour is different in this case - the original file1
continues to exist in its previous location.
To learn more, you can check man mv
and man cp
A nice option for learning - you can get mv
and cp
to tell you what they are doing by making them verbose: adding -v
. Here I move the file chocolate
from the current working directory ~/playground
to my Desktop with the verbose option, and I get some output in the terminal:
zanna@monster:~/playground$ mv -v chocolate ~/Desktop
'chocolate' -> '/home/zanna/Desktop/chocolate'