[英]How to copy files from a linux directory to another given a length parameter
I have no knowledge of linux commands but I am currently trying to copy all files with a length of 11 (not including extension) from one directory to another.我不知道 linux 命令,但我目前正在尝试将长度为 11(不包括扩展名)的所有文件从一个目录复制到另一个目录。
I am trying to files from a directory called "~cs/pub" to my home directory "~"我正在尝试将文件从名为“~cs/pub”的目录到我的主目录“~”
I have found online things like find and grep but cannot find any issues similar enough to mine for me to be able to figure out what to do.我在网上找到了 find 和 grep 之类的东西,但找不到任何与我的问题相似的问题,让我能够弄清楚该怎么做。
Any information helps.任何信息都有帮助。 I have seen a lot of posts about copying files based on other requirements like date made or contains a certain character but those wont help as I don't understand linux well enough yet我已经看到很多关于根据其他要求(例如制作日期或包含某个字符)复制文件的帖子,但这些帖子无济于事,因为我还不太了解 linux
tldr; tldr; test the regex测试正则表达式
$ ls | grep -E ^.{11}$
If those are the files use the regex to copy them如果这些是文件,请使用正则表达式复制它们
$ ls | grep -E ^.{11}$ | xargs cp -t /MY_PATH
For a more detailed review如需更详细的评论
$ ls
list the files列出文件
$ grep -E ^.{11}$
is a regex on the the file name.是文件名的正则表达式。 It requires the file have 11 charters (of any type)它要求文件有 11 个章程(任何类型)
$ xargs cp -t /MY_PATH
Will re write the matching paths to the follow form cp -t /MY_PATH (matching files).将匹配路径重新写入以下形式 cp -t /MY_PATH (匹配文件)。
And that is all it takes.这就是它所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.