V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Martin9
V2EX  ›  Linux

[linux] 如何批量复制文件名中有$符号的文件

  •  1
     
  •   Martin9 · May 11, 2016 · 5151 views
    This topic created in 3638 days ago, the information mentioned may be changed or developed.

    有个 file_list 文件,里面写了需要复制的文件名, 使用 while read line 会自动忽略$符号, 求助下各位,谢谢

    Supplement 1  ·  May 11, 2016
    谢谢大家的帮忙,已送铜币表示感谢, 5 楼是我想要的答案
    Supplement 2  ·  May 12, 2016
    诸位,不好意思又来求助大家。
    按照 5 楼的方法能在本地成功。
    然而因为 file_list 文件和需要复制的文件不在一个服务器上,所以 ssh 到文件所在的服务器上时, file_list 文件名中由于有$符号导致不能正确传输,
    请问有方法能解决么?
    Supplement 3  ·  May 12, 2016


    代码如上,客户名和服务器名手动打码,应该没有影响
    11 replies    2016-05-11 20:35:46 +08:00
    fish47
        1
    fish47  
       May 11, 2016   ❤️ 1
    用 xargs -d SEP 不就好了?再不行就用 python 呗。
    dixyes
        2
    dixyes  
       May 11, 2016 via Android   ❤️ 1
    木有转义?\$之类的?
    Martin9
        3
    Martin9  
    OP
       May 11, 2016
    @fish47 不能用 python,只能用 shell
    Martin9
        4
    Martin9  
    OP
       May 11, 2016
    @dixyes read line 的时候$line 这个变量读文件名的时候会忽略$,
    McContax
        6
    McContax  
       May 11, 2016 via Android
    shell 脚本即可
    ilotuo
        7
    ilotuo  
       May 11, 2016   ❤️ 1
    试下单引号
    其内部所有的 shell 元字符、通配符都会被关掉。注意,硬转义中不允许出现’(单引号)。
    ilotuo
        8
    ilotuo  
       May 11, 2016
    ^_^[18:35:48]develop$ touch '$tetst'
    ^_^[19:06:27]develop$ ls '$tetst'
    $tetst
    ^_^[19:06:34]develop$ rm '$tetst'
    cxbig
        9
    cxbig  
       May 11, 2016   ❤️ 1
    转义\$

    整个文件名加引号
    Martin9
        10
    Martin9  
    OP
       May 11, 2016
    @SpicyCat 多谢
    Martin9
        11
    Martin9  
    OP
       May 11, 2016
    @cxbig 想批量做, 5 楼这样的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5753 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 06:41 · PVG 14:41 · LAX 23:41 · JFK 02:41
    ♥ Do have faith in what you're doing.