在 Linux 中,如何复制所有不以给定字符串开头的文件? [英] In Linux, how to copy all the files not starting with a given string?

查看:29
本文介绍了在 Linux 中,如何复制所有不以给定字符串开头的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下命令:

cp src_folder/[!String]* dest_folder

但是,此命令将复制所有不以任何字符 'S','t','r','i','n','g' 开头的文件,而不是复制不以任何字符开头的文件不要以字符串"开头.

However, this command will copy all the files that don't start with any of the characters 'S','t','r','i','n','g' instead of copying files that don't start with "String".

推荐答案

Konrad 答案的变体,使用 cp 选项 -t 指定目标目录简化了最后一个命令.它创建了一个 cp 进程来复制所有文件.

A variation on Konrad answer, using cp option -t to specify target directory simplifies the last command. It creates a single cp process to copy all the files.

ls src_folder | grep -v '^String' | xargs cp -t dest_folder

  • 列出src_folder
  • 中的所有文件
  • 过滤掉所有以String
  • 开头的
  • 将所有剩余文件复制到dest_dir
  • 这篇关于在 Linux 中,如何复制所有不以给定字符串开头的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆