简体   繁体   English

如何查找某些文件并将其复制到文件夹中?

[英]How to find certain files and copy them in a folder?

I have a folder (name250) which contains several sub-directories. 我有一个包含几个子目录的文件夹(name250)。 I want my script to find certain files (tE1_sys_250.txt to tE99_sys_250.txt) in all the sub-directories and copy them in another folder (name250_sys). 我希望我的脚本在所有子目录中找到某些文件(tE1_sys_250.txt到tE99_sys_250.txt),然后将它们复制到另一个文件夹(名称250_sys)中。

This is my script but when I run it nothing happens. 这是我的脚本,但是运行时什么也没发生。

#!/bin/bash
cd ~/name250/
mkdir ../name250_sys
for a in {10..99}
do
`find . -name tE$a'_sys'_250.txt -exec cp {} ./name250_sys/ \;`
done

Thanks in advance. 提前致谢。

This looks wrong: 这看起来是错误的:

cd /name250/

That would attempt to change the directory to a "name250" directory contained in the root folder. 这将尝试将目录更改为根文件夹中包含的“ name250”目录。 I imagine you want: 我想你想要:

cd ../name250_sys

I found the solution. 我找到了解决方案。 my problem was the last part of the script which I had to add a line " cd .." before find command. 我的问题是脚本的最后一部分,我必须在find命令之前添加一行“ cd ..”。 Then, it works. 然后,它起作用。

#!/bin/bash
cd ~/name250/
mkdir ../name250_sys
cd ..
for a in {10..99}
do
`find . -name tE$a'_sys'_250.txt -exec cp {} ./name250_sys/ \;`
done

Try if following one line will help: 尝试以下一行是否有帮助:

if you are looking for 1-99 如果您正在寻找1-99

find . -regextype posix-awk -regex '.*tE[0-9]{1,2}_sys_250\.txt' -exec cp {} ./name250_sys/ \;

and if you are looking for 10-99 如果您正在寻找10-99

find . -regextype posix-awk -regex '.*tE[0-9]{2}_sys_250\.txt' -exec cp {} ./name250_sys/ \;

Assuming you are only looking to copy such files 假设您只想复制此类文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bash:查找包含特定字符串的文件并将它们复制到文件夹中 - Bash: Find files containing a certain string and copy them into a folder 如何在列表中查找包含使用部分名称的目录和子目录中的所有文件,然后将它们复制到新文件夹 - How to find all files in a directory and subdirectories that contain using partial names within a list then copy them to a new folder 按名称查找文件夹然后复制文件 - Find folder by name then copy files 如何按文件类型递归查找文件并将它们复制到目录? - How to find files recursively by file type and copy them to a directory? 在目录中的文件中找到字符串,然后将其复制 - find string inside files in a dir then copy them 使用查找将文件复制到新文件夹 - Use find to copy files to a new folder 如何在一定时间内复制带有一定后缀的文件? - how to copy files with certain suffix for a certain times? 如何在当前目录中查找以“ y”和“ .txt”结尾的文件(仅文件)并将其移动到其他文件夹? - How to find files (files only) with the ending 'y' and '.txt' in the current directory and move them to a different folder? 如何找到各个子文件夹中的所有tar文件,然后将它们解压缩到找到的同一文件夹中? - How to find all tar files in various sub-folders, then extract them in the same folder they were found? 如何在单个命令中复制一定范围的文件? - How to copy certain range of files in single command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM