

There are a number of concerns to be aware of when using cp. Recursively copy the contents of a directory, including subdirectories, to a different target directory.Copy multiple files to a different target directory.It is possible to rename the file or retain the old name. Copies a file to a different directory.The command operates in four basic modes. The cp command works similarly on most Linux distributions. How to Use the cp Command to Copy Files and Directories in Linux If you are not familiar with the sudo command, see the Users and Groups guide. Commands that require elevated privileges are prefixed with sudo.

This guide is written for a non-root user. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access. See our Getting Started with Linode and Creating a Compute Instance guides.įollow our Setting Up and Securing a Compute Instance guide to update your system. If you have not already done so, create a Linode account and Compute Instance. Users must have sudo privileges to copy protected files. cp has a number of options, allowing users to run it interactively, use verbose mode, or preserve the file attributes of the original. The -r option enables the cp command to operate recursively and copy a directory along with any files and subdirectories it contains. It is also possible to give the copy a different name than the original file. The cp command allows users to copy a file to either the same directory or a different location. Like most Linux commands, cp is run using the command line of a system terminal. It is similar to the mv command, except it does not move or remove the original file, which remains in place. The cp command is used to copy one or more files on a Linux system to a new location. It also lists the different variations of this command and describes the different cp command options. This guide explains how to use the cp command to copy files on Linux. Ubuntu and other Linux distributions use the cp command to copy one or more files, and to copy entire directories. Copying a file is one of the most common Linux tasks.
