This guide will go through how to move or copy a directory in Linux. One can achieve copy and pasting when working with Linux through the graphical user interface(GUI) by clicking or even using keyboard shortcuts but when it comes to Linux servers where you are using a terminal, the commands come in handy even when you just want to feel the geeky part of you when using the GUI.
MV Command
- To move a directory using the move command use the example below. The command will move the folder named Demo to the Documents directory in the itnixpro user.
mv Demo /home/itnixpro/Documents
- You can also use the mv command to move a file from one location to another.
mv demofile.txt /home/itnixpro/Documents
- The mv command can move a folder with all files and subfolders in it without adding the -r option.
mv /home/itnixpro/Documents/Demo /home/itnixpro/Downloads
CP Command
- In the example below, we will go through how to copy a directory in Linux. To copy a directory using the cp command add the -r option as shown below.
cp -r Directory /home/itnixpro/Documents
- Copy and paste multiple directories.
cp -r 1Directory 2Directory /home/itnixpro/Documents
- Copy all files inside a directory by adding the
*
symbol.
cp -r Directory/* /home/itnixpro/Documents
- That concludes our article on how to move or copy a directory in Linux.
Read more about MV Command on the man pages
Read more about CP Command on the man pages