简体   繁体   English

找到一个文件并将其复制到另一个目录

[英]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.

相关问题 如何查找一个用户拥有的所有文件并将它们复制到 RHEL 8 中的另一个目录? - How to find all file owned by one user and copy them to another directory in RHEL 8? 查找具有条件的最大文件并将其复制到特定目录 - Find the biggest file with criteria and copy it to a specific directory 在目录中查找文件副本到新文件名 - Find files in a directory copy to a new file name Ansible:将文件复制到另一个用户的主目录 - Ansible: Copy file into another users home directory 尝试将目录中的第n个文件复制到另一个文件夹 - Trying to copy the nth file in a directory to another folder “查找”目录下的所有.log文件,将它们复制到以其父目录命名的另一个目录? - 'find' all .log files under a directory, copy them to another directory named after their parent directory? CentOS:将目录复制到另一个目录 - CentOS: Copy directory to another directory 如果文件不在另一个目录中,则将文件复制到目录 - Copy files to directory if they are not in another directory 如何按文件类型递归查找文件并将它们复制到目录? - How to find files recursively by file type and copy them to a directory? 如何在整个目录中查找具有特定扩展名的文件,然后将其复制到另一台服务器 - How to look for a file with a particular extension in the entire directory and then copy to another server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM