我有一个目录(<很多)
类型的子目录pageChanged
在每个子目录中我有一个名为“density.cube”的文件
我想将所有“density.cube”移动到一个新的子目录“td”
中td.0000000
td.0000050
td.0000100
etc.
或至少
td/density0000000.cube
td/density0000050.cube
td/density0000100.cube
etc.
我怎么能实现这一目标?我有bash和python的基础,但显然还不够......
谢谢!
答案 0 :(得分:0)
这个bash脚本可以帮助你:
# create the td directory
mkdir td
# for every subdirectory of name td.*
for file in td.*
do
# get its number
number=$(echo $file | cut -d'.' -f 2)
# and move the density.cube from that subdir to td with new name
mv $file/density.cube td/density${number}.cube
done
答案 1 :(得分:0)
您可以使用find命令。
find /your/path/here/to/the/parent/directory/that/has/all/the/folders -name density.* type f -exec cp {} /path/to/where/you/wanna/move/them +
-name匹配您想要获取
的文件的名称-type f只匹配文件而不是具有该名称的文件夹
-exec允许您对结果执行任何命令
cp linux中的copy命令
{}替换find命令的结果(匹配的文件)
+在匹配的每个文件上运行该exec命令。