How to copy a folder to another folder in Linux: 1. Copy the contents of folder A to folder B through the "cp -r" command; 2. Copy the contents of the A file to the folder B through the "cp -r" command Copy the contents of the folder to the B folder; 3. Delete all the contents of the A folder through the "rm -rf" command; 4. Move the A folder to the B folder through the "mv" command.
#The operating system of this tutorial: linux5.18.14 system, Dell G3 computer.
How to copy a folder to another folder in Linux
1. Copy all the contents of one folder to another folder
cp -r /home/packageA/* /home/cp/packageB/ 或 cp -r /home/packageA/. /home/cp/packageB/
The effect of these two methods is the same.
Method example:
2. Copy one folder to another folder
cp -r /home/packageA /home/packageB
After running the command, packageB folder There is a packageA folder under it.
Method example:
3. Delete a folder and all the files under it
rm -rf /home/packageA
-r means to Recurse, no matter how many levels of directories there are, delete them all
-f means direct forced deletion without any prompt
Method example:
4. Move a folder to another folder
mv /home/packageA /home/packageB/ 或 mv /home/packageA /home/packageB
The effect of these two methods is the same.
Method example:
5. Move all the contents under one folder to another folder
mv /home/packageA/* /home/packageB/
Method example:
The above is the detailed content of How to copy a folder to another folder in linux. For more information, please follow other related articles on the PHP Chinese website!