[英]find a file and copy it to another directory
I have a directory called main
.我有一个名为main
的目录。 This directory is located in the root I mean the path to this directory is like this: /HOME/main
这个目录位于根目录我的意思是这个目录的路径是这样的: /HOME/main
Inside this directory there is a folder called f1
and inside it another folder called subf1, so the path is like this: /HOME/main/f1/subf1
在这个目录里面有一个文件夹叫f1
,里面有另一个文件夹叫subf1,所以路径是这样的: /HOME/main/f1/subf1
I want to check if there is a file in subf1
with a name containing a special string and copy this file to the main
directory.我想检查subf1
是否有名称包含特殊字符串的文件,并将此文件复制到main
目录。 I use this:我用这个:
find . -maxdepth 1 -name "*string*" -exec cp {} ../main \;
It's incomplete and I don't know how to check if condition here, but even when I execute this command in /HOME/main/f1/subf1
path, it doesn't work.它不完整,我不知道如何在这里检查条件,但是即使我在/HOME/main/f1/subf1
路径中执行此命令,它也不起作用。 what's wrong?怎么了?
你可以这样使用它:
find /HOME/main/f1/subf1 -iname "*string*" -exec cp {} /HOME/main/ \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.