How to Copy Files and Folders in Linux (Ubuntu)
The copy command in Linux is “cp”? (Without quotes that is)
Examples uses:
Example #1 – Copy network files and folders from network shares to a Linux directory.
This example assumes that you have mapped (Mounted) the target network share in Linux. If you have not already done this I suggest you do this prior to moving forward.
If you don’t know how to map a network drive or a network share on a windows server, then you can get a quick tutorial from a previous article I wrote on How to map and mount network drives and windows shares.
Those less experienced and new to Linux may end up creating bottlenecks on their network by trying to copy large files and folders from the Windows share to the Linux folder via a Windows PC running SFTP or other such tool. Where the data has to go from the windows share to the laptop and then back out to the target Linux directory.
So back to the example. If you have now mapped a windows share on your Linux box then lets move forward.
Assuming your mount on the Linux box is at?’/media/winshare’ which is mapped to ‘//windowsserver/shares/winshare’ , also assuming you have read and write permissions all correct, you can begin to copy files from windows share to the Linux box.
To copy and entire folder from the root of the share to a desired Linux folder, you will need to execute the following command:
$ cd /media/winshare
(Change to Windows Share Mount Directory)
:/media/winshare$ ls
(List all Files and Folders in the Windows Mount Share Directory)
:/media/winshare$ Accounting Sales Marketing HR Data
(Shows all present Files and Directories)
:/media/winshare$ sudo cp -r Accounting ‘/data’
(Copies the Accounting folder to the Linux Folder . the -r instructs to copy recursively)
Example #2 – Copy a file to same folder and rename it in one single command.
This example assumes that you wish to edit a file, but wish to preserve the original file (just in case)
execute the following command:
$ cp origfile copyoforigfile
This will make a exact copy of “origfile” and name it “copyoforigfile”, but the file “origfile” will no be moved, modified or changed in any way.
and that is it… Enjoy