Copy all files in the specified directory to another directory
The copying of files and directories is often used. The commands for copying under Linux are CP.
Assume that the replication source directory is dir1 and the destination directory is DIR2. How can I copy all the files under the Dir1 to Dir2?
If the Dir2 directory does not exist, you can use it directly
Cp-r Dir1 Dir2
Can.
If the Dir2 directory already exists, you need to use the
Cp-r dir1/. Dir2
If the Cp-r dir1 Dir2 is used at this point, the Dir1 directory will also be copied to Dir2, which is clearly not in line with the requirements.
Ps:dir1, Dir2 change to the corresponding directory path.
Example 2
Copy the specified file to the specified folder
First create a directory for testing, and use the ' tree ' command to view
It can be seen that the catalog contains *.txt files for testing and * for serving as cannon fodder. TES file
The goal is to keep the current directory structure, just copy the TXT file.
Method One: When you do not need a single file type, you can complete the file by completely copying and then deleting the specified type
Step1 Use the command cp-r test/test2 to completely copy all the contents of the test catalog to Test2
STEP2 combination use Find and xargs to delete the *.tes file
Xargs is a filter that passes parameters to the command, which can be the output from the previous command as a parameter of the latter command
Command find test2/-name ' *.tes ' |xargs rm-rf, the output that will be generated by the find (all TES files under the Test2 directory), as an RM parameter, thus completely removed
Example of a scenario: Backing up a project file, removing the. svn file from it, can be used this way
Linux CP Replication