Home > Operation and Maintenance > Linux 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
Release: 2023-06-08 16:35:05
Original
53945 people have browsed it

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/
Copy after login

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
Copy after login

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
Copy after login

-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
Copy after login

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/
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template