[英]Unix script moving files to folders
I have a folder work and the below script searches for .txt or .csv files and moves the files into completed folder.我有一个文件夹工作,下面的脚本搜索 .txt 或 .csv 文件并将文件移动到已完成的文件夹中。 I created one more folder (APEX) inside work folder, but the files from APEX folder are not moving to the completed folder and giving below error.我在工作文件夹中又创建了一个文件夹 (APEX),但是 APEX 文件夹中的文件没有移动到已完成的文件夹并出现以下错误。 I would like all the .txt or .csv files in my-test-folder/work and my-test-folder/work/APEX files to be moved to my-test-folder/done.I do not have a folder /my-test-folder/completed/APEX/ ,nor I want the files to be moved there.我想将 my-test-folder/work 和 my-test-folder/work/APEX 文件中的所有 .txt 或 .csv 文件移动到 my-test-folder/done.I 没有文件夹 /my -test-folder/completed/APEX/ ,我也不希望将文件移动到那里。
Error : mv: cannot move
./my-test-folder/work/APEX/test1.txt
to./my-test-folder/completed/APEX/test1.txt
: No such file or directory错误:mv:无法将./my-test-folder/work/APEX/test1.txt
移动到./my-test-folder/completed/APEX/test1.txt
:没有这样的文件或目录
find . -path "*work*" \( -iname "*.txt" -o -iname "*.csv" \) -exec bash -c "mv {} \`echo {} | sed -e 's/work/completed/g' \` " \;
If you don't want to keep the same directory hierarchy in my-test-folder/completed
as in my-test-folder/work
, you can simplify your command:如果您不想在my-test-folder/completed
中保持与my-test-folder/work
相同的目录层次结构,您可以简化您的命令:
find full/path/to/work -iname "*.txt" -o -iname "*.csv" -exec mv "{}" full/path/to/completed \;
Note that this will not remove empty directories left after moving all the files out.请注意,这不会删除移出所有文件后留下的空目录。 You can do this if you are using GNU find with the following command:如果您使用带有以下命令的 GNU find,则可以执行此操作:
find work -empty -delete
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.