


In this case, you can use –backup option to back up any existing destination file during the copying process.


Backup a Destination Fileīy default, the cp command will overwrite the file on the destination directory if the same file exists. If you want to preserve mode, ownership, and timestamps after copying files and directories, you can use -p option: cp -arp /etc/apache2 /opt 6. You can also use -a option to archive the files and directory during the copy. You can use option -r with cp command to copy files and directory recursively. This will not prompt for the overwrite and also will not overwrite the existing file. If you don’t want to overwrite an existing file, you can use the option -n. You should see the following output: cp: overwrite '/mnt/crontab'? yes This option will prompt you before copying the file to the destination directory if the same file already exists. If you want to copy a file interactively, use the option -i with cp command. You should see the following output: '/etc/hosts' -> '/mnt/hosts' If you want to display verbose output during the copying process, run the following command: cp -v /etc/hosts /etc/hostname /mnt If you want to copy multiple files named /etc/hosts and /etc/hostname at the same time to the /mnt directory, run the following command: cp /etc/hosts /etc/hostname /mnt You should see your file in the following output: -rw-r-r- 1 root root 1042 Jun 21 11:32 crontab 2. You can now verify it with the following command: ls -l /mnt If you want to copy a single file named /etc/crontab to the /mnt directory, run the following command: cp /etc/crontab /mnt -u : Copy only when the SOURCE file is newer.-f : Remove an existing destination file if it can not be opened.-i : You will be prompted before overwriting any existing file on the destination.-a : Copy files and directories recursively and preserve links.The basic syntax of the cp command is shown below: cp Ī brief explanation of each available option is shown below: Once you are logged into your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 1GB RAM. A root password configured on your server.įirst, log in to your Atlantic.Net Cloud Server.A fresh Ubuntu 20.04 VPS on the Cloud Platform.In this tutorial, we will show you how to use the cp command to copy files and directories in Linux. By default, the cp command is available in almost all Unix- and Linux-like operating systems. The cp command is a basic Linux command used for copying files and directories from one location to another. If you are a system administrator, copying files and directories is one of the most common tasks in your day-to-day work.
