Home  >  Article  >  Operation and Maintenance  >  How to copy a folder to another folder in linux

How to copy a folder to another folder in linux

Robert De Niro
Robert De NiroOriginal
2023-06-08 16:35:0553872browse

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.

How to copy a folder to another folder in linux

#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:

How to copy a folder to another folder in linux

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:

How to copy a folder to another folder in linux

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:

How to copy a folder to another folder in linux

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:

How to copy a folder to another folder in linux

5. Move all the contents under one folder to another folder

mv /home/packageA/* /home/packageB/

Method example:

How to copy a folder to another folder in linux

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn