It is quite easy to copy, move or rename a file using the command line interface (cli, terminal, and shell are other names used to refer to the command line).Use the command
You can copy a file to a different folder using just the same command. Here is an example:
cp example.txt example2.txt
cp example.txt /var/www/documents/example.txt
Moving and renaming
In order to move files, use the command mv. Just type "mv", the name of the file to be moved and the name the moved file will get. For example: to move the file example.txt to the folder /var/www, do the following:
It is important to notice that you may move and rename at the same time, by simply changing the name of the resulting file:
mv example.txt /var/www/example.txt
That is why renaming and moving are just the same thing. If you want just to rename a file, you simply move it to the same folder. Nice, isn't it?. Here is the example:
mv example.txt /var/www/renamed.txt
Some very important extra infoThere are four important thing you must know about this procedure
- It is quite powerfull for you may use it to move, copy and rename lots of files at once, thus it is worthwhile learnig
- Once a file is moved, there is no "undo". When moving lots of files you must be very carefull
- File and folders names may not have space chars in them, unles they are between quotation marks. Ex:
cp "important file.txt" "/var/www/important folder/important file.txt"
- If you want to copy an entire folder you will need to add at the end of the command a "-R". This means the command will be recursive, that is, you will copy the folder and everything in it.