First note these two things:
Code:
Windows / Generic Terminoloty <------> Unix/Linux Terminology
Cut (file/directory) <------> Move (file/directory)
Paste (only in Editor) <------> Put (such as in Vi or Vim)
Now, let me show you how to move a file from a directory to some other directory.
I am currently in this directory:
Code:
[demo@localhost ~]$ pwd
/home/demo
[demo@localhost ~]$
I have a file in /tmp directory:
Code:
[demo@localhost ~]$ ls /tmp/hello
/tmp/hello
[demo@localhost ~]$
Now I will move the above file into my current directory as shown below:
Code:
[demo@localhost ~]$ mv /tmp/hello .
[demo@localhost ~]$ ls hello
hello
[demo@localhost ~]$
Notice the dot (.) which means the current directory specified in place of the destination directory/location.
Now let's move the file back to its previous location:
Code:
[demo@localhost ~]$ mv hello /tmp
[demo@localhost ~]$ ls hello
ls: cannot access hello: No such file or directory
[demo@localhost ~]$ ls /tmp/hello
/tmp/hello
[demo@localhost ~]$
This time I have specified the destination directory's name/location. The file is not in the current directory hence you see the error above. It is back in the /tmp directory.
Before moving, you can check what you are going to move:
Code:
[demo@localhost ~]$ echo mv /tmp/h*
mv /tmp/hello
[demo@localhost ~]$
Use "echo" command as shown above. It saves your time and helps you see what exactly will happen. The above result means there is one file that begins with "h" and if I remove the "echo" part then it will be moved to my current directory.
To avoid overwriting a file if it is already present in the destination directory, do this:
Code:
[demo@localhost ~]$ mv -i /tmp/hello .
mv: overwrite `./hello'? n
[demo@localhost ~]$
Did you get it?
Note: If you do not provide a destination directory name then the file will be
renamed:
Code:
[demo@localhost ~]$ mv /tmp/hello /tmp/hi
[demo@localhost ~]$ ls /tmp/h*
/tmp/hi
[demo@localhost ~]$
You should visit
www.tldp.org and download/view the Linux Introduction guide from/on there.