{"id":12996,"date":"2021-12-21T08:07:16","date_gmt":"2021-12-21T08:07:16","guid":{"rendered":"https:\/\/linuxways.net\/?p=12996"},"modified":"2021-12-21T08:07:20","modified_gmt":"2021-12-21T08:07:20","slug":"how-to-copy-multiple-files-using-cp-command-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/scripting\/how-to-copy-multiple-files-using-cp-command-in-linux\/","title":{"rendered":"How to Copy Multiple Files Using cp command in Linux"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>The cp command in Linux is used to copy files and directories by using the command line. This command also allows you to move multiple files and folders at once while preserving their backup and attribute information. So the cp command is very useful for Linux users.<\/p>\n<p>Now we&#8217;re gonna guide you about copying multiple files using the cp command in Linux. Hope you understand.<\/p>\n<h2>Syntax to copy a file of the cp command<\/h2>\n<pre>$ cp [filename] [filename2]<\/pre>\n<p>For example, we&#8217;ll see what&#8217;s in our current directory by the ls command<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"92\" class=\"wp-image-12997\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-270.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-270.png 969w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-270-300x28.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-270-768x73.png 768w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/><\/p>\n<p>Now, we will copy the hello.pl file:<\/p>\n<pre>$ cp hello.pl hello1.pl<\/pre>\n<p>Then use the ls command to check:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"971\" height=\"105\" class=\"wp-image-12998\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-271.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-271.png 971w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-271-300x32.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-271-768x83.png 768w\" sizes=\"auto, (max-width: 971px) 100vw, 971px\" \/><\/p>\n<h2>Syntax to copy multiple files of the cp command<\/h2>\n<p>You must provide a filename and destination directory to do this.<\/p>\n<p>The syntax:<\/p>\n<pre>$ cp [filename] [filename1] [folder name]\/<\/pre>\n<p>For example, we&#8217;ll see what&#8217;s in our current directory by the ls command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"967\" height=\"86\" class=\"wp-image-12999\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-272.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-272.png 967w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-272-300x27.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-272-768x68.png 768w\" sizes=\"auto, (max-width: 967px) 100vw, 967px\" \/><\/p>\n<p>We will copy hello.pl and hello1.pl files into the test directory.<\/p>\n<pre>$ cp hello.pl hello1.pl test\/<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"86\" class=\"wp-image-13000\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-273.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-273.png 970w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-273-300x27.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-273-768x68.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/p>\n<h2>Syntax to copy a directory of the cp command<\/h2>\n<p>To copy the directory we must use the -r option:<\/p>\n<pre>$ cp -r foldername\/ foldername 1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"92\" class=\"wp-image-13001\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-274.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-274.png 969w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-274-300x28.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-274-768x73.png 768w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/><\/p>\n<p>Now we will try to copy the test directory:<\/p>\n<pre>$ cp -r test\/ test2<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"107\" class=\"wp-image-13002\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-275.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-275.png 970w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-275-300x33.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-275-768x85.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/p>\n<h2>Syntax to copy multiple directories of the cp command<\/h2>\n<p>The syntax:<\/p>\n<pre>$ cp -r foldername foldername 1 foldername 2<\/pre>\n<p>The destination folder will be at the end.<\/p>\n<p>For example:<\/p>\n<pre>$ cp -r test test2 testfinal<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"970\" height=\"131\" class=\"wp-image-13003\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-276.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-276.png 970w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-276-300x41.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-276-768x104.png 768w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/p>\n<p>In the above example, we copied test and test2 folders into testfinal folder.<\/p>\n<h2>Backup when copying files<\/h2>\n<p>Let\u2019s use the -b option to backup when copying files:<\/p>\n<pre>$ cp -b [filename] [filename2]<\/pre>\n<p>For example, we will backup the hello.pl file:<\/p>\n<pre>$ cp -b hello.pl hellobk.pl<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"964\" height=\"130\" class=\"wp-image-13004\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-277.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-277.png 964w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-277-300x40.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/12\/word-image-277-768x104.png 768w\" sizes=\"auto, (max-width: 964px) 100vw, 964px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>And we guided you on how to copy multiple files using the cp command in Linux.<\/p>\n<p>Thank you for checking it out!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction The cp command in Linux is used to copy files and directories by using the command line. This command also allows you to move multiple files and&hellip;<\/p>","protected":false},"author":1,"featured_media":13276,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[769,35],"class_list":["post-12996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-cp-command","tag-linux"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/12996","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=12996"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/12996\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/13276"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=12996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=12996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=12996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}