Problem: Some data in my server need find out to copy to the mobile hard disk, and keep the original directory structure, find./-name ' * '-exec cp-v--parents {}/mnt \; I wrote that,./Sub-directories will be created in/mnt, the problem is that I need to create a subdirectory in the/mnt/to build another directory data, and then the directory in the contents of the database in the folder in the directory, and finally the/mnt/created subdirectory/data/ Atomic directory of data, how to use shell script how to achieve, younger brother rookie, hope Master advice.
You can split the two-time find operation, create a directory at a time, and copy the data in a second loop. For example: First time: Find./-name ' * '-type d-exec cp-v--parents {}/mnt \; second: for dir in/mnt/*;d ofind./${dir}-name ' * '-type f -exec cp-v--parent {}/mnt/${dir} \;d One
Ask:
abcd12234, Hello, because I was just in touch with Linux, only know some basic commands, Shell script What do not understand, these two commands can be placed in a file to execute it? How do you write a script for me?
Chase Answer:
#!/bin/bashfind./-name ' * '-type d-exec cp-v--parents {}/mnt \;for dir in/mnt/*;d ofind./${dir}-name ' * '-type F- exec cp-v--parent {}/mnt/${dir} \;d One puts two commands directly into a piece and throws it into a file, the top comment is the shebang line, which tells Bash that the program needs to explain that it can add executable permissions to sudo. chmod +x./filename execution:./filename
Ask:
Hello, I tried, the first command of Find./-name ' * '-type d-exec cp-v--parents {}/mnt \; It seems that there is something wrong, can't get the directory structure, how can you first copy the directory structure to find the files to temporarily not copy files? Like you said, the first step is to copy the directory structure of the file, and the second one is to copy the file into it and ask for advice.
Chase Answer:
All you have to do with the directory structure is to get rid of the beginning of the-exec, just do it: find./-name ' * '-type D
This article is from the "lake and Laughter" blog, please make sure to keep this source http://hashlinux.blog.51cto.com/9647696/1791567
Problems with copying Linux data to a removable hard disk