Chinaunix

标题: 如何写这个复制命令 [打印本页]

作者: yufeiluo    时间: 2017-01-05 09:51
标题: 如何写这个复制命令
    ls -a /var/www/html/wp
    .                ..                    .git
    index.php        wp-blog-header.php    wp-cron.php        wp-mail.php
    license.txt      wp-comments-post.php  wp-includes        wp-settings.php
    readme.html      wp-config.php         wp-links-opml.php  wp-signup.php
    wp-activate.php  wp-config-sample.php  wp-load.php        wp-trackback.php
    wp-admin         wp-content            wp-login.php       xmlrpc.php

我想将/var/www/html/wp目录下面除去.git外,说有的文件递归复制到   /tmp/test
ls -a /var/www/html/wp|grep -v  '.git'
可以删除.git文件

这个命令可以复制
ls  /var/www/html/wp |grep -v '.git' |xargs -i  cp -r  {}  /tmp/test/{}
但是,复制完成后,文件结构全部变了。

    debian8@hwy:/var/www/html/wp$ ls  /tmp/test
    about.php               load-styles.php         revision.php
    admin-ajax.php          maint                   setup-config.php
    admin-footer.php        media-new.php           term.php
    admin-functions.php     media.php               theme-editor.php
    admin-header.php        media-upload.php        theme-install.php
    admin.php               menu-header.php         themes.php
    admin-post.php          menu.php                tools.php
    async-upload.php        moderation.php          update-core.php
    comment.php             ms-admin.php            update.php
    credits.php             ms-delete-site.php      upgrade-functions.php
    css                     ms-edit.php             upgrade.php
    custom-background.php   ms-options.php          upload.php
    custom-header.php       ms-sites.php            user
    customize.php           ms-themes.php           user-edit.php
    edit-comments.php       ms-upgrade-network.php  user-new.php
    edit-form-advanced.php  ms-users.php            users.php
    edit-form-comment.php   my-sites.php            widgets.php
    edit-link-form.php      nav-menus.php           wp-activate.php
    edit.php                network                 wp-admin
    edit-tag-form.php       network.php             wp-blog-header.php
    edit-tags.php           options-discussion.php  wp-comments-post.php
    export.php              options-general.php     wp-config.php
    freedoms.php            options-head.php        wp-config-sample.php
    images                  options-media.php       wp-content
    import.php              options-permalink.php   wp-cron.php
    includes                options.php             wp-includes
    index.php               options-reading.php     wp-links-opml.php
    install-helper.php      options-writing.php     wp-load.php
    install.php             plugin-editor.php       wp-login.php
    js                      plugin-install.php      wp-mail.php
    license.txt             plugins.php             wp-settings.php
    link-add.php            post-new.php            wp-signup.php
    link-manager.php        post.php                wp-trackback.php
    link-parse-opml.php     press-this.php          xmlrpc.php
    link.php                profile.php
    load-scripts.php        readme.html
    debian8@hwy:/var/www/html/wp$ ls  /var/www/html/wp
    index.php        wp-blog-header.php    wp-cron.php        wp-mail.php
    license.txt      wp-comments-post.php  wp-includes        wp-settings.php
    readme.html      wp-config.php         wp-links-opml.php  wp-signup.php
    wp-activate.php  wp-config-sample.php  wp-load.php        wp-trackback.php
    wp-admin         wp-content            wp-login.php       xmlrpc.php

我不想这样做
    cp  -r  /var/www/html/wp/   /tmp/test
    rm /tmp/test/.git



作者: haooooaaa    时间: 2017-01-05 09:59
  1. rsync -avz  /var/www/html/wp/   /tmp/test --exclude='.git'
复制代码

作者: moperyblue    时间: 2017-01-05 10:09

  1. find /var/www/html/wp -mindepth 1 ! -name "*.git" -exec cp -r {} /tmp/test \;
复制代码

?
作者: yufeiluo    时间: 2017-01-05 11:11
find /var/www/html/wp -mindepth 1 ! -name "*.git" -exec cp -r {} /tmp/test
find: missing argument to `-exec'

作者: moperyblue    时间: 2017-01-05 11:24
回复 4# yufeiluo


find /var/www/html/wp -mindepth 1 ! -name "*.git" -exec cp -r {} /tmp/test \;
作者: yufeiluo    时间: 2017-01-05 11:31
最后这个  \;   我无法理解

作者: blackold    时间: 2017-01-07 10:53
回复 1# yufeiluo

ls  /var/www/html/wp |grep -v '.git' |xargs -i  cp -r  {}  /tmp/test/{}

这命令执行时不会出错吗?



作者: blackold    时间: 2017-01-07 10:54
回复 1# yufeiluo

ls  /var/www/html/wp |grep -v '.git' |xargs -i  cp -r  {}  /tmp/test/{}

这命令执行时应该出错啊。

作者: blackold    时间: 2017-01-07 10:54
回复 1# yufeiluo

ls  /var/www/html/wp |grep -v '.git' |xargs -i  cp -r  {}  /tmp/test/{}

这命令执行里应该不正常啊。

作者: blackold    时间: 2017-01-07 10:55
回复 1# yufeiluo

ls  /var/www/html/wp |grep -v '.git' |xargs -i  cp -r  {}  /tmp/test/{}

这命令执行里应该


有问题。

作者: blackold    时间: 2017-01-07 10:55
回复 1# yufeiluo

命令没写对。

作者: blackold    时间: 2017-01-07 10:56
本帖最后由 blackold 于 2017-01-07 10:58 编辑

我引用LZ的命令后发贴老是出错


汗,出错也发贴成功了,晕。

作者: sditmaner    时间: 2017-01-07 13:18
好帖子顶一顶!感谢楼主

作者: bikkuri    时间: 2017-01-08 12:01
直接cp -r /var/www/html/wp/* /tmp/test/就可以了,/var/www/html/wp/.git是隐藏文件,不会被拷贝。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2