Home>Article>Operation and Maintenance> How to copy files using cp command in linux
In Linux, you can use the cp command to copy files and copy the source file or directory to the specified destination file or directory; it can copy a single source file into a specific file with a specified file name or an existing file. directory; this command supports copying multiple files at the same time.
#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.
cp command format
##Take moving file 1234.txt as an examplels -l //显示当前文件夹下所有文件的信息Copy 1234.txt file to new file 2345.txt
copy 1234.txt 2345.txtHere you can see that the two files have the same size but different timestamps Copy the 1234.txt file to the new file 3456.txt and keep the timestamp the same What happens if the new file name after copying already exists? After writing some content to 1234.txt and copying it to 2345.txt again, you will find that the original 2345.txt file will be overwritten and there will be no reminder and the execution will be successful. To avoid not knowing whether a file with the same name has been overwritten, you can add the -i option Example:
cp -i 1234.txt 3456.txtYou can see when the new When the file name already exists in the current directory, there will be an overwrite confirmation reminder. Enter n to cancel and continue copying. Copy files to folders in the same directory and other folders in different directories
cp 123.txt test //同目录 cp 1234.txt /home/zinkky/test //不同目录时需要带上路径Copy directories to The new directory needs to add the option -r Example:
cp -r test python(recommended learning:
linux tutorial)
The above is the detailed content of How to copy files using cp command in linux. For more information, please follow other related articles on the PHP Chinese website!