{"id":9002,"date":"2026-05-30T01:56:15","date_gmt":"2026-05-29T23:56:15","guid":{"rendered":"https:\/\/mybox.com\/help\/?post_type=manual_kb&#038;p=9002"},"modified":"2026-05-30T01:56:16","modified_gmt":"2026-05-29T23:56:16","slug":"comenzi-ssh-cp","status":"publish","type":"manual_kb","link":"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/","title":{"rendered":"Comenzi SSH - cp"},"content":{"rendered":"<div class=\"translation-block translation-block-merged\">\n<p class=\"wp-block-paragraph\">In server administration, backend web development, and cloud systems engineering, creating precise duplicates of your configuration files, script models, or media assets is a vital routine. The <strong><code>cp<\/code><\/strong> command stands for <strong>Copy<\/strong>. It is a core POSIX-standard terminal utility used to replicate files and directories from a specified source location to a target destination within your server&#8217;s filesystem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using this utility allows you to create safe backups of critical configuration blocks before performing major updates, ensuring you can quickly rollback if an issue occurs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#Direct_Copy_Operations_and_Primary_Command_Flags\" >Direct Copy Operations and Primary Command Flags<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#1_Copying_Entire_Folders_Recursively_cp_-r\" >1. Copying Entire Folders Recursively (cp -r)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#2_Safeguarding_Existing_Files_with_Interactive_Mode_cp_-i\" >2. Safeguarding Existing Files with Interactive Mode (cp -i)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#3_Preserving_File_Attributes_cp_-p\" >3. Preserving File Attributes (cp -p)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#Working_with_Absolute_Brand_Directory_Paths\" >Working with Absolute Brand Directory Paths<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#Creating_an_Immediate_Security_Backup\" >Creating an Immediate Security Backup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mybox.com\/help\/ro\/knowledgebase\/ssh-commands-cp\/#Replicating_a_File_to_a_Separate_Project_Folder\" >Replicating a File to a Separate Project Folder<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Direct_Copy_Operations_and_Primary_Command_Flags\"><\/span>Direct Copy Operations and Primary Command Flags<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<\/div>\n\n<div id=\"mybox-573533002\" class=\"mybox-content mybox-entity-placement\"><div class=\"early-access-banner-inpost\">\r\n  <div class=\"banner-left-inpost\">\r\n    <div class=\"icon-box-inpost\">\r\n      <img decoding=\"async\" src=\"https:\/\/mybox.com\/help\/wp-content\/uploads\/2026\/02\/square-info-icon.svg\" alt=\"Info\">\r\n    <\/div>\r\n    <div class=\"text-box-inpost\">\r\n      <span class=\"label-inpost\"><span class=\"translation-block translation-block-banner-text\">Acces timpuriu<\/span><\/span>\r\n      <h4><span class=\"translation-block translation-block-banner-text\">Mai ave\u021bi nevoie de ajutor?<\/span><\/h4>\r\n      <p><span class=\"translation-block translation-block-banner-text\">Contacta\u021bi echipa noastr\u0103 de servicii pentru clien\u021bi.<\/span><\/p>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"banner-right-inpost\">\r\n    <a href=\"https:\/\/panel.mybox.com\/helpdesk2\/v\/list\/\" class=\"banner-button-inpost\"><span class=\"translation-block translation-block-banner-text\">Trimite mesaj<\/span><\/a>\r\n  <\/div>\r\n<\/div><\/div>\n\n<div class=\"translation-block translation-block-merged\"><p class=\"wp-block-paragraph\">The basic syntax for a copy operation requires passing a source path followed immediately by a destination path: <code>cp source_file destination_file<\/code>. To adapt the command for multi-file transfers, directory tree backups, or safety verification steps, you will regularly append these core operational flags:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Copying_Entire_Folders_Recursively_cp_-r\"><\/span>1. Copying Entire Folders Recursively (<code>cp -r<\/code>)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default, running <code>cp<\/code> on a folder will result in an error because the command only targets individual files. To copy a directory along with all of its nested subfolders, files, and assets, you must use the <code>-r<\/code> (recursive) flag.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The Action:<\/strong> Run the recursive flag followed by your source folder and destination path:Bash<code>cp -r production_files\/ staging_backup\/<\/code><\/li>\n\n\n\n<li><strong>Operational Benefit:<\/strong> This is the primary method used to duplicate a complete website layout or media library into a safe backup folder within your environment.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Safeguarding_Existing_Files_with_Interactive_Mode_cp_-i\"><\/span>2. Safeguarding Existing Files with Interactive Mode (<code>cp -i<\/code>)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If your target destination directory already contains a file with the exact same name as the file you are moving, the standard <code>cp<\/code> command will overwrite it without warning. The <code>-i<\/code> (interactive) flag forces the server to pause and ask for confirmation before overwriting any data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The Action:<\/strong> Add the safety filter to your execution string:Bash<code>cp -i config.env backups\/config.env<\/code><\/li>\n\n\n\n<li><strong>The Prompt Returned:<\/strong> The terminal will stop and display a message like <code>overwrite backups\/config.env? (y\/n)<\/code>. You must type <code>y<\/code> and press Enter to approve the overwrite, or <code>n<\/code> to safely cancel the operation.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Preserving_File_Attributes_cp_-p\"><\/span>3. Preserving File Attributes (<code>cp -p<\/code>)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When you duplicate a file, the server normally assigns the current time as the new creation date and resets the file&#8217;s user ownership to the active account running the command. The <code>-p<\/code> (preserve) flag copies the file while maintaining its original modification timestamps, access permissions, and ownership flags.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The Action:<\/strong> Execute the preservation flag over sensitive system files:Bash<code>cp -p system_script.sh archive\/system_script.sh<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Working_with_Absolute_Brand_Directory_Paths\"><\/span>Working with Absolute Brand Directory Paths<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can copy assets across any directory tree on the server by leveraging absolute paths. When working inside your brand architecture, ensure you map your routes correctly starting from your home base:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_an_Immediate_Security_Backup\"><\/span>Creating an Immediate Security Backup<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before editing your environment file, create a localized backup copy with a <code>.bak<\/code> extension appended to the filename:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp \/home\/mybox\/yourlogin\/public_html\/.env \/home\/mybox\/yourlogin\/public_html\/.env.bak\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Replicating_a_File_to_a_Separate_Project_Folder\"><\/span>Replicating a File to a Separate Project Folder<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To copy an optimized assets file from one website directory into an entirely separate subfolder branch inside your brand environment, use explicit destination target pathing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp custom-styles.css \/home\/mybox\/yourlogin\/yourwebsite.com\/public_html\/assets\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"template":"","format":"standard","manualknowledgebasecat":[54],"manual_kb_tag":[1180,1592,6174,6175,6208,6210,6211,6212,6213,6214],"class_list":["post-9002","manual_kb","type-manual_kb","status-publish","format-standard","hentry","manualknowledgebasecat-ssh","manual_kb_tag-server-administration","manual_kb_tag-file-permissions","manual_kb_tag-backend-web-development","manual_kb_tag-cloud-systems-engineering","manual_kb_tag-interactive-mode","manual_kb_tag-copy-command","manual_kb_tag-file-copy","manual_kb_tag-directory-copy","manual_kb_tag-recursive-copy","manual_kb_tag-preserve-attributes"],"_links":{"self":[{"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/manual_kb\/9002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/manual_kb\/9002\/revisions"}],"predecessor-version":[{"id":9003,"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/manual_kb\/9002\/revisions\/9003"}],"wp:attachment":[{"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/media?parent=9002"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/manualknowledgebasecat?post=9002"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/mybox.com\/help\/ro\/wp-json\/wp\/v2\/manual_kb_tag?post=9002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}