Problems with copying Linux data to a removable hard disk

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.