How to Copy Files and Folders in cPanel and via Command Line Make it Rain Paper

  • cPanel File Manager, cPanel File Management, SSH
  • 0

Pre-requirements

  • Access to your cPanel account or SSH for command line usage.
  • Basic understanding of file paths and folder structures in cPanel or Linux command line.

Copying Files Using cPanel File Manager

If you have already created a web hosting account and logged in to your cPanel account, follow these steps to copy files using the cPanel File Manager:

  1. Scroll down to the Files section and click on the File Manager icon.
  2. Select the files or folders you want to copy by clicking on them. (Note: You cannot create a copy of a file with the same name in the same folder).
  3. Once selected, click on the Copy option in the toolbar at the top of the File Manager.
  4. You can also right-click on the selected files and choose Copy from the menu.
  5. In the popup interface, enter the destination file path in the Enter the file path that you want to copy this file to: text box.
  6. Click Copy File(s) to complete the process and copy the files to the new location.

Gotchas to Avoid

  • Ensure you are not copying a file to the same location without renaming it. Otherwise, it will cause conflicts.
  • Make sure that you have permission to write to the destination directory before copying the files.

Copying Files Using the Command Line (SSH)

If you prefer to use the command line, the cp command is a powerful tool for copying files and directories. Here's how to do it:

Basic Command to Copy a File

To copy a single file and receive a prompt before overwriting an existing file:

cp -i fileName1 destinationPath

Example:

If you want to copy contact.html to /about/contact-us.html:

cp -i contact.html /about/contact-us.html

Copy Only Specific File Types

To copy all .php files to a specific directory:

cp -i *.php public_html/about

Copy Multiple Files at Once

To copy multiple files to a destination directory, list the files separated by spaces and the final path will be treated as the destination:

cp -i filename1.txt filename2.txt public_html/about

Copying Directories Recursively

To copy a directory and all its contents, including subdirectories, use the -R (recursive) flag:

cp -iR public_html/legal public_html/about

Copying All Files and Directories in a Source Directory

To copy all files and directories in a directory to another location, use a wildcard (*):

cp -iR public_html/legal/* public_html/about

Gotchas to Avoid

  • Always use the -i flag to prompt you before overwriting files. This prevents accidental data loss.
  • Ensure you have write permissions in both the source and destination directories to avoid permission errors.
  • Double-check the destination path to avoid copying files to unintended locations.

Helpful Tip for Using cp Command

If you're unsure about how to use the cp command for your task, you can reference the manual by typing:

man cp

If you still need assistance, you can use the "cp code generator" at Rapidtables.com to create the correct syntax for your copying task.

Copying files and directories in cPanel or via the command line is a straightforward process when you follow the steps outlined above. Use the cPanel File Manager for a visual, user-friendly method, or use the command line for more control and flexibility. Be mindful of file paths, permissions, and potential overwrites to ensure a smooth experience.

If you want to add to this tutorial or have found an error in it, please send an email to team+editorial@webhostingm.com


Did this answer help?

« Back