[Linux] How to Copy Folders and Move Folders

The commands for copying, moving and deleting files under linux are: cp, mv, rm
1. File copy command cp

Command format: cp [- adfilprsu] source file (source) destination file (destination)
cp [option] source1 source2 source3 ... directory

Parameter description:
-a: refers to the meaning of archive, which means to copy all directories
-d: if the source file is a link file (link file), copy the attributes of the link file instead of the file itself
-f: force (force) , if there is duplication or other doubts, the user will not be asked, but forced to copy
-i: if the destination file (destination) already exists, it will first ask whether the operation is really done when overwriting
-l: establish a hard link (hard link) Link files instead of copying the file itself
-p: copy with file attributes instead of using default attributes
-r: recursive copy for directory copy operations
-s: copy as a symbolic link file (symbolic link), ie " "shortcut" file
-u: if the target file is older than the source file, update the target file 


For example, copy file1 in the /test1 directory to the /test3 directory and change the file name to file2, enter the following command:
cp /test1/file1 /test3/file2


Second, the file move command mv

Command format: mv [-fiv] source destination

Parameter description:
-f: force, force direct move without asking
-i: if the destination file (destination) already exists, it will ask whether to overwrite
-u: if the destination file already exists and the source file is relatively new, it will be updated


If you copy file1 in the /test1 directory to the /test3 directory and change the file name to file2, you can enter the following command:
mv /test1/file1 /test3/file2


3. File deletion command rm

Command format: rm [fir] file or directory

Parameter description:
-f: forced deletion
-i: interactive mode, ask the user whether to operate before deletion
-r: recursive deletion, commonly used in directory deletion


To delete the file1 file in the /test directory, you can enter the following command:
rm -i /test/file1



copy:
复制代码
CP command
Format: CP [options] source file or directory destination file or directory
Option description: - b with the same name, back up the original file
         - f forcibly overwrite the file with the same name
         - r recursively retain the original directory structure and copy the file

cp -Rf /home/user1/* /root/temp/
Copy everything in the /home/user1 directory to /root/temp/ without copying the user1 directory itself.
That is, the format is: cp -Rf original path/destination path/
复制代码

move:

复制代码
mv ./WorkReport/web.xml ./WorkReport/WEB-INF/ 
Note: Move the /WorkReport/web.xml file to /WorkReport/WEB-INF/

mv /data/new /data/old/
注:移动/data/new 到/data/old/文件夹下
注意点:移动文件夹的话就不要再加 /

如果是移动文件夹下的所有文件的话就可以文件夹后面跟上 /* 

mv /data/new/* /data/old/
复制代码

 本文转载自:https://www.cnblogs.com/liaojie970/p/6746230.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324605232&siteId=291194637