V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
sisyphus60
V2EX  ›  Linux

linux 下使用 cp 指令遇到问题

  •  
  •   sisyphus60 · 2015-05-18 15:30:55 +08:00 · 2416 次点击
    这是一个创建于 3271 天前的主题,其中的信息可能已经有所发展或是发生改变。

    执行一段指令如下:复制一个文件夹A下所有的文件(不要文件夹),碰巧A下有一个文件夹名字为cache,有一个文件名字叫cache.img。在服务器上测试工作正常,在搭建的Hudson环境中运行该指令不行,遇到cache文件时会报错:omitting directory

    ls $dir|grep -v "^d"|grep -v "zip$"|while read i
    do
    cp $dir/$i $dest/$container
    done

    请问这是什么节奏,我查看Hudson中bash的版本和服务的bash版本是一致的。这个情况怎么破?

    5 条回复    2015-05-20 18:00:03 +08:00
    czheo
        1
    czheo  
       2015-05-18 15:44:06 +08:00
    ls后面加-l
    sisyphus60
        2
    sisyphus60  
    OP
       2015-05-18 18:34:02 +08:00
    @czheo 为什么会这样呢?
    czheo
        3
    czheo  
       2015-05-18 18:40:54 +08:00
    你在开发机上输入type ls看看,有提示
    extreme
        4
    extreme  
       2015-05-18 23:58:59 +08:00
    我觉得奇怪,ls只显示文件名吧,后面的过滤根本不起作用。
    cp不带-a复制带内容的文件夹就会出现那个提示,也就是跳过该文件夹,不处理。
    试试这个:
    OLD_PATH="被复制的文件所在的文件夹"
    NEW_PATH="复制到的文件夹"
    for i in $(find ${OLD_PATH} -type f -maxdepth 1)
    do
    cp ${i} ${NEW_PATH} && echo "Copy ${i} to ${NEW_PATH} successfully." || echo "Copy ${i} to ${NEW_PATH} unsuccessfully."
    done
    sisyphus60
        5
    sisyphus60  
    OP
       2015-05-20 18:00:03 +08:00
    @extreme 已经搞定,多谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2216 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:27 · PVG 19:27 · LAX 04:27 · JFK 07:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.