I am trying to copy the contents of a folder to another folder in a different directory using terminal.
Would somebody be able to provide me an example of the command line syntax required to achieve this?
I am trying to copy the contents of a folder to another folder in a different directory using terminal.
Would somebody be able to provide me an example of the command line syntax required to achieve this?
You can copy the content of a folder
/source
to another existing folder/dest
with the commandThe
-a
option is an improved recursive option, that preserve all file attributes, and also preserve symlinks.The
.
at end of the source path is a specificcp
syntax that allow to copy all files and folders, included hidden ones.An alternate is
rsync
:The advantages of
rsync
are:Lets say you have a folder called folder1 in your
~
, inside folder1 is 1 file called file1 and 2 folders called sub1 and sub2 each with other files and folders inside them.To copy all the contents of
~/folder1
to~/new_folder1
you would usenew_folder1
would then contain all the files and folders fromfolder1
.cp
is the command to copy using a terminal,-r
makes it recursively (so, current directory + further directories inside current)~/folder1
is the origin folder,~/new_folder1
is the destination folder for the files/folders inside the origin.Simple example.
Copy the directory dir_1 and its contents (files) into directory dir_2:
Copy only the contents (files) of dir_1 into directory dir_2:
_files_
is a placeholder for the actual files located in the directory.Check this http://www.cyberciti.biz/faq/copy-folder-linux-command-line/ for more information on copying folder. Hope this helps.
cp
is a Linux command for copying files and directories. The syntax is as follows:In this example copy
/home/vivek/letters
folder and all its files to/usb/backup
directory:Where,
-a
: Preserve the specified attributes such as directory an file mode, ownership, timestamps, if possible additional attributes: context, links, xattr, all.-v
: Explain what is being done.-r
: Copy directories recursively. ExampleCopy a folder called /tmp/conf to /tmp/backup:
I like this command
If there are two folders: (with write permission)
If you are inside the folder called PORTAL where you want to copy all content of another folder say DATA at the same level then you will do
vimal@vimal-D3H:/var/www/html/PORTAL$ cp -a ../DATA/. .
You have to notice 2 dots. Last dot says copy here in present folder
and
one following /DATA/. says that all the CONTENTS inside DATA folder to be copied, and not the DATA folder itself.
If you remove this trailing "." from /DATA/
then whole DATA folder will be copied inside PORTAL(from where you are coping).
This code with Flag "-R" copies perfectly all the contents of "folder1" to existing "folder2":
Flag "-R" copies symbolic links as well but Flag "-r" skips symbolic links so Flag "-R" is better than Flag "-r".