{"id":18170,"date":"2022-08-22T11:03:03","date_gmt":"2022-08-22T11:03:03","guid":{"rendered":"https:\/\/linuxways.net\/?p=18170"},"modified":"2022-09-05T16:56:42","modified_gmt":"2022-09-05T16:56:42","slug":"copy-directory-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/copy-directory-linux\/","title":{"rendered":"Copy Directory Linux"},"content":{"rendered":"<p>Just like files in Linux, the directories can be moved from one location using different methods. This guide will enlighten you on the method of copying a directory in Linux.<\/p>\n<h2><strong>How can you Copy a Directory in Linux?<\/strong><\/h2>\n<p>You will have to follow the method described below to copy a directory along with its contents to another directory in Linux:<\/p>\n<h3><strong>Step # 1: Learn the Usage of the \u201ccp\u201d Command in Linux<\/strong><\/h3>\n<p>The \u201ccp\u201d command in Linux is used for copying a directory from one location to another. However, before copying our desired directory to another, we will first learn the usage of the \u201ccp\u201d command by running the following command:<\/p>\n<pre>\r\n$ cp --help\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"312\" height=\"22\" class=\"wp-image-18188\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-1.png 312w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-1-300x21.png 300w\" sizes=\"auto, (max-width: 312px) 100vw, 312px\" \/><\/strong><\/p>\n<p>This command will display the help manual of the \u201ccp\u201d command on your terminal from where you will be able to learn all the options that can be used with the \u201ccp\u201d command as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"411\" class=\"wp-image-18189\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-2.png 645w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-2-300x191.png 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n<h3><strong>Step # 2: List the Contents of the Directory that you Need to Copy to Another Directory<\/strong><\/h3>\n<p>Now, we would like to show you the contents of the directory which we wish to copy to another. For that, we have executed the following command:<\/p>\n<pre>\r\n$ ls \/home\/system\/Directory1\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"446\" height=\"27\" class=\"wp-image-18190\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-3.png 446w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-3-300x18.png 300w\" sizes=\"auto, (max-width: 446px) 100vw, 446px\" \/><\/strong><\/p>\n<p>The contents of our directory &#8220;Directory1&#8221; are shown in the image below. This output will help us in verifying the correctness of the copying process.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"459\" height=\"63\" class=\"wp-image-18191\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-4.png 459w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-4-300x41.png 300w\" sizes=\"auto, (max-width: 459px) 100vw, 459px\" \/><\/p>\n<h3><strong>Step # 3: Copy the Target Directory to the Directory of your Choice<\/strong><\/h3>\n<p>We will use the following command for copying the directory \u201cDirectory1\u201d to another directory \u201cDirectory2\u201d:<\/p>\n<pre>\r\n$ cp \u2013r \/home\/system\/Directory1 \/home\/system\/Directory2\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"44\" class=\"wp-image-18192\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-5.png 645w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-5-300x20.png 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/strong><\/p>\n<p>This command will recursively copy all the contents of the target directory along with the directory itself to the other directory. However, no output will appear on the terminal as shown in the image below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"57\" class=\"wp-image-18193\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-6.png 645w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-6-300x27.png 300w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/p>\n<h3><strong>Step # 4: List the Contents of the Latter Directory<\/strong><\/h3>\n<p>Now, to verify if \u201cDirectory1\u201d has been successfully copied to \u201cDirectory2\u201d, we will list the contents of \u201cDirectory2\u201d with the help of the following command:<\/p>\n<pre>\r\n$ ls \/home\/system\/Directory2\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"22\" class=\"wp-image-18194\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-7.png 440w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-7-300x15.png 300w\" sizes=\"auto, (max-width: 440px) 100vw, 440px\" \/><\/strong><\/p>\n<p>The output shown in the image below implies that \u201cDirectory1\u201d now resides inside \u201cDirectory2\u201d. However, we are still unsure about whether the contents of \u201cDirectory1\u201d have successfully been copied to \u201cDirectory2\u201d or not. Therefore, we will also perform the next step.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"60\" class=\"wp-image-18195\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-8.png 470w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-8-300x38.png 300w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<h3><strong>Step # 5: Expand the Contents Listing of the Latter Directory to Ensure the Correctness of the Copying Process<\/strong><\/h3>\n<p>In this step, we will recursively list the contents of the directory residing inside \u201cDirectory2\u201d i.e., \u201cDirectory1\u201d to know whether the contents of the latter directory have successfully been copied or not. For that, we will run the following command:<\/p>\n<pre>\r\n$ ls \u2013R \/home\/system\/Directory2\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"25\" class=\"wp-image-18196\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-9.png 463w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-9-300x16.png 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/strong><\/p>\n<p>The output shown in the image below verifies that the copying process has taken place successfully i.e., \u201cDirectory1\u201d has been copied to \u201cDirectory2\u201d along with all of its contents.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"495\" height=\"133\" class=\"wp-image-18197\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-10.png 495w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18170-10-300x81.png 300w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>This article was meant to guide you about the method of copying a directory in Linux. After learning this method, you will conveniently be able to copy directories from one location to another.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>This article is on the method of copying a directory in Linux for you to conveniently be able to copy directories from one location to another.<\/p>","protected":false},"author":3,"featured_media":18198,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-18170","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18170"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18170\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18198"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}