从一个子目录中的文件移动到另一个 [英] Moving files from one subdirectory to another

查看:319
本文介绍了从一个子目录中的文件移动到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个目录移动到另一个文件,并没有工作。所以我搜索,找到了答案适合我想要的。当我运行它,修改为我的目录,它给

I tried moving files from one directory to another and didn't work. so I searched and found an answer that fits what I want. When I run it, modified to my directory, it gives

什么是想要做的:

$ {文件名,, *} :替代不好

这是我用什么:

for filename in *; do
  case "${filename,,*}" in
    b01.nii*)    mv "$filename" "$/Users/dave/Desktop/test/untitled_folder_*/str" ;;
    vol_01.nii*) mv "$filename" "$/Users/dave/Desktop/test/untitled_folder_*/rs" ;;
    *)           echo "don't know where to put $filename";;
  esac
done

感谢您

推荐答案

在两个错误:

主要的问题是指挥,变量 $文件名包含 * 而不是真正的文件名。你应该usefor名在 $(找到-name*);做

the main problem is the for command, the variable $filename contains * and not the real file name. you should usefor filename in $(find . -name "*");do

第二个是这样的:

您必须确保关于 $文件名变量的值,即在我的Bash shell文件名输出

you have to be sure about $filename variable's value i.e. in my bash shell the filename output is

./b01.nii 
./vol_01.nii 

这是更好地使用以下语法的情况下 ./ b01.nii *)

我已经更换了你 MV 回声只是为了测试脚本:

I've replaced your mv with echo just to test the script:

for filename in $(find . -name "*"); do

  case ${filename} in
    ./b01.nii* )    
                echo "$filename ${filename}/Users/dave/Desktop/test/untitled_folder_*/str" ;;
    ./vol_01.nii* ) 
                echo "$filename ${filename}/Users/dave/Desktop/test/untitled_folder_*/rs" ;;
    *)          
                echo "don't know where to put $filename";;
  esac
done

我的输出

sh-4.3$ bash -f main.sh                                                                                                                                                                                                                                 
don't know where to put .                                                                                                                                                                                                                               
don't know where to put ./main.sh                                                                                                                                                                                                                       
don't know where to put ./.cg_conf                                                                                                                                                                                                                      
don't know where to put ./myfile_12345                                                                                                                                                                                                                  
don't know where to put ./myfile_17676                                                                                                                                                                                                                  
don't know where to put ./myfile_9898                                                                                                                                                                                                                   
don't know where to put ./Newfile.sh                                                                                                                                                                                                                    
./b01.nii ./b01.nii/Users/dave/Desktop/test/untitled_folder_*/str                                                                                                                                                                                       
./vol_01.nii ./vol_01.nii/Users/dave/Desktop/test/untitled_folder_*/rs 

问候

克劳迪奥

这篇关于从一个子目录中的文件移动到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆