What is Linux Copy Command How To Use Step By Step

What is Linux Copy Command How To Use Step By Step

Linux and other Linux distributions The cp command is used to copy a single file, group file, directory from one location to another. With the help of this command, you can copy the file from one location to another with any other name where the data of the file will not change, only the name of the file will change.

Syntax:

cp [OPTIONS] SOURCE DESTINATION

Copy Single File

  • If you want to copy the file from one place to another first write the cp command then after the cp command type the name of the source file which you want to copy and then Write the destination path where you want to paste the copy file.
cp Source_File_Name Dest_File_Name
cp File1 /root
cp command in linux

Copy more than One File

  • If You want to copy multiple files from one location to another, First Write the Cp command, then you have to write the name of all the files with a signal space, and then Write the destination Path.
cp data1 data2 data3 data4 /home
copy multiple file in linux
  • If you want to copy the directory from one place to another, then for this you have to use the R option after the CP command
cp -R Src_directory Dest_Path
cp -R TECH /Root
copy Directory in linux
  • i(interactive) I mean interactive copy, if you want to overwrite with the file that exists in the destination location, you have to use the R option. Before overwriting the file, the system will take the confirmation from the user and the user has to type ‘y’
cp -i data1 /root
Copy File in linux with interactive option
  • -f(force)If you are not able to copy regular or another Special Permission File and you want to copy files and directories forcefully then you should use the ‘f’ option.
Copy  File in Linux File with Force Fully
  • v(Verbose) if you want to see the process of copying files and Directory From source to Destination then Use the -v option.
cp -rvi /etc /root
Copy File in linux with Verbose Option
  • Copying using * wildcard The * wildcard represents anything. If you have lots of files and directories in your source location and want to copy all those files and dirs to destination, then you have two options, the first way is to copy files one by one and the second smart way is this That you can use a * wildcard to copy all the files located in the source at once. As you can see below, 5 files have been copied together with the help of * wildcard.
cp data* /home
Copy File in linux With * WildCard
  • R (recursive) If you want to copy all the files and subdirectories created inside the directory then use the -R option.
cp -rvi Source_Dir Destination_Path
cp -rvi /etc/ /var
Copy File in linux with recursive Option

Conclusion

Now we have learned how to copy files from one location to another with the help of the Linux cp command. To know more options related to this command, run the man cp command.
share copy file and Directory over the network use SCP (Secure Copy) and sync. If have any doubts, Questions,s, and Feedback related to this article feel free to leave a comment.

Also Read : Linux Basic Command with Example

Also, Visit Our Other Blog Simiservice.com

Rate this post
simi kaithal