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