The copy (cp) and move (mv) commands in Linux

For some reason, when you look for a way to move a folder and all it’s sub folders into another folder, overwriting the files if they exist on destination, you will find very little information, the reason behind that is that the mv command that both renames files and folders and moves them does not support the -R switch (Recursive), the answer is that you copy them, then delete the source

So, if i downloaded wordpress and i want to update my installation with the new files i would

cp -R /var/vhosts/wordpress/* /var/vhosts/example.com/

this will update my copy of wordpress by moving the contents of the wordpress folder into the virtual hosting directory of my website

KEEP IN MIND THAT THE mv AND cp COMMANDS OVERWRITES WITHOUT PROMPTING….

to make it prompt before overwriting you must provide a -i parameter

If you don’t want a prompt, and you still want to NOT overwrite destination files… you will need to also set the “–reply=no” (depreciated) parameter so that the mv command will answer NO to all overwrite situations

NOTE: –reply has been depreciated (no longer works)

the linux move (mv) command : Moving folders

to move a folder into another folder, assuming there is a file names text.txt inside the folder /hds/ssd/mysql/moveme/text.txt, after this command we will have the file in /hds/ssd/mysql/into/moveme/text.txt

mv /hds/ssd/mysql/moveme/ /hds/ssd/mysql/into/

To move the contents of moveme including sub-folders directly into the folder into without moving the folder moveme itself

mv /hds/ssd/mysql/moveme/* /hds/ssd/mysql/into/

Leave a Reply

Your email address will not be published. Required fields are marked *