Copying files in Linux
Copying files and folder is an essential task for every user, No matter what operating system you use. In this article, We will see how we can copy the Files or Folders using the Linux terminal.

Copying files and folder is an essential task for every user, No matter what operating system they are using. In this article, We will see how we can copy the Files or Folders using the Linux terminal.
This will be really useful when you work on Linux servers that don't have GUI.
The method we are covering here applies to all Linux-based distros like Linux Mint, CentOS, Fedora. It's like Learn once, use it anywhere.
Alright, Let's dive in.
cp
is the command-line utility in Linux for copying the files using the terminal.
cp
takes multiple arguments such as current file path, destination.
Copying a single file from one path to another using terminal
Here is an example command for copying green1.jpg
from folder A to folder B
cp /home/letsfoss/A/green1.jpg /home/letsfoss/B/
This is what the above command is doing:
cp
is the copying command-line utility/home/letsfoss/A/green1.jpg
is the current file path/home/letsfoss/B/
is the path I want to copy the files to.
When you enter this command and press enter the file will be copied to the specified path
Copying a folder/directory using terminal
Copying a folder takes another argument -R
which means recursive files.
See this example to under it better.
In this example, I want to copy everything from folder1
to the myfolder
in my home directory.
cp -R /folder1 /home/letsfoss/myfolder/
Let's understand what is happening.
cp
is the command-line utility for copying files-R
is for recursive files and folders/folder1
is the folder, I want to copy/home/letsfoss/myfolder/
is the location I want to copy the files to.
When you enter this command. It'll copy the whole folder to the location you have specified without changing the folder structures.
If you have any doubt, please comment below.
Related Articles


