【问题标题】:How to copy files with prefix '-'?如何复制带有前缀'-'的文件?
【发布时间】:2014-09-10 06:30:55
【问题描述】:

我试图通过简单地发出“cp * /dst_dir”来复制目录下的所有文件,但Shell显示:

~/git$ cp * ~/dst_dir
cp: invalid option -- 'o'

然后发出“ls -1”列出所有文件,发现罪魁祸首是一些带有前缀'-'的文件,如下所示。

   -count
   -sdds
   ...

不知道这些文件是如何生成的,而且我仍然找不到删除或移动这些“-xxx”文件的方法。

   ~/git$ rm "-count"
   rm: invalid option -- 'c'
   Try `rm ./-count' to remove the file `-count'.
   Try `rm --help' for more information.

   ~/git]$ mv \-count  /tmp
   mv: invalid option -- 'c'
   Try `mv --help' for more information.

顺便说一句,我的外壳是 RHEL 6.3 上的 TCSH,“tcsh --version”显示:

    ~/git]$ tcsh --version
    tcsh --version
      tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,color,filec

任何人都对这个问题有任何线索。非常感谢您的帮助。

更新

谢谢大家。刚才查了手册,官方给出的答案如下:

   To remove a file whose name starts with a '-', for example '-foo',  
   use one of these commands:

      rm -- -foo

      rm ./-foo

【问题讨论】:

标签: linux file shell unix


【解决方案1】:

尝试命令rm -- -countrm ./-count,查看rm 的手册页。同样,cp -- * ~/dst_dir 复制文件

【讨论】:

    【解决方案2】:

    与往常一样,指定完整路径。

    rm ./*
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2021-04-28
      • 2020-11-24
      相关资源
      最近更新 更多