Copying files in Linux

Copying files in Linux

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.

πŸ”₯ Get Free updates about Linux on Telegram πŸ”₯
We send Linux Memes, Articles and, Open Source projects. No Random Spam Links. Click to Join

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.

πŸ”₯ Get Free updates about Linux on Telegram πŸ”₯
We send Linux Memes, Articles and, Open Source projects. No Random Spam Links. Click to Join

How to use SCP to tranfer files securely in the Terminal
SCP stands for Secure Copy Protocol it’s based on SSH which allows us to access the remote system over the secure connection. The Good thing about SSH is we can connect to the remote system and execute the commands.
How to Generate Password in Linux
There are a ton of Password generators out there, In both online and offline. But you can easily generate strong passwords in your Linux terminal.
Fix: Temporary failure in name resolution
Problem: Suddenly, I’m got DNS failure issue in Google Chrome. I tried to ping Google from Terminal Here is the error I got. ninja@softinttech:~$ ping google.com ping: google.com: Temporary failure in name resolution Here is the Fix for this issue. Open the Terminal and Run the following