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

藏色散人
藏色散人 Original
2023-01-04 14:14:38 29297browse

How to copy a folder to another folder in Linux: 1. Open a terminal command window; 2. Copy the folder packageA to the packageB file through the "cp -r /home/packageA /home/packageB" command Just clip it.

How to copy a folder to another folder in linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

How to copy a folder to another folder in Linux?

Linux Copy a folder or all the contents under a folder to another folder

1. Copy all the contents of one folder to another folder

cp -r /home/packageA/* /home /cp/packageB/
or
cp -r /home/packageA/. /home/cp/packageB/
These two methods have the same effect.

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, there will be thepackageAfolder under thepackageBfolder. .

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

  • -rmeans downward recursion, no matter how many levels of directories there are, delete them all
  • -fmeans direct forcible 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/
or
mv / home/packageA /home/packageB
These two methods have the same effect.

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

Recommended study: "Linux Video Tutorial"

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