
Omitting the slash on the source directory will copy the contents into a subdirectory.

This copies the contents of the /etc/docker/ directory to /home/backup/docker/. To copy a directory with rsync, enter the following: rsync –a /etc/docker/ /home/backup/docker/ Using my_file_backup.txt as the target indicates the file will be renamed during the copy.Replace /new_directory/ with the destination.Replace the my_file.txt file in the working directory.The –a option means all, and is included with rsync commands – this preserves subdirectories, symbolic links, and other metadata.To copy a single file, enter the following into a terminal: rsync –a my_file.txt /new_directory/my_file_backup.txt Usage is similar to cp, but there are a few key differences to note. The rsync command in Linux is used to synchronize or transfer data between two locations.

–R stands for recursive, which means “everything in that location.” This would copy all the files, as well as all the directories, to the / new_directory folder.

However, the same file cannot exist twice in the same directory. This Linux command creates a copy of the my_file.txt file and renames the new file to my_file2.txt.īy default, the cpcommand runs in the same directory you are working in. The basic format of the command is: cp source_file target_file Virtually all Linux distributions can use cp. The cp command is the primary method for copying files and directories in Linux. Using the cp Command to Copy Files and Directories in Linux If your version of Linux boots to a desktop graphical interface, launch a terminal window by pressing CTRL-ALT-F2 or CTRL-ALT-T. Note: These Linux commands can only be run from a terminal window.
