Copying

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 cp to copy. Type cp followed by the name of the file you want to copy, and then the name you want to give to the new copy. Here is an example: in order to create a new copy of the file "example.txt" named "example2.txt", do the following:
cp example.txt example2.txt
You can copy a file to a different folder using just the same command. Here is an example:
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:

mv example.txt /var/www/example.txt
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/renamed.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 examplo.txt renamed.txt

Some very important extra info

There are four important thing you must know about this procedure
  1. It is quite powerfull for you may use it to move, copy and rename lots of files at once, thus it is worthwhile learnig
  2. Once a file is moved, there is no "undo". When moving lots of files you must be very carefull
  3. 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"
  4. 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.
comments powered by Disqus