I need a solution for this script to move files that will drop into the 8953-x folders to a joint folder. The files that drops to the 8953-x folders will automatically be moved to the joint folder /mnt/FOLDER.

It will move all files besides files containing ! in their filename, for example picture.jpg.!sync. Files ending with .!sync are in sync between servers, using btsync and not complete, they shall be ignored. When the sync end, the file output will change to picture.jpg, and then I want it to be transferred to the joint folder.

#!/bin/bash

from_folders=(8953-10  8953-11  8953-12  8953-3  8953-4  8953-5  8953-6  8953-7  8953-8  8953-9)
${from_folders[@]}
有帮助吗?

解决方案

I believe this should work, but please test on a backup directory.

shopt -s extglob; mv 8953-*/!(\!*) /mnt/FOLDER

This turns on pattern matching and then moves all files in those folders which do not start with exclamation to the destination folder.

If the files all are named .jpg when ready, it is easier:

 mv 8953-*/*.jpg /mnt/FOLDER

其他提示

This is an improved script:

#!/bin/bash

shopt -s extglob

from_folders=(8953-10  8953-11  8953-12  8953-3  8953-4  8953-5  8953-6  8953-7  8953-8  8953-9)
for folder in ${from_folders[@]}
do
echo mv $folder/!(\!*) /mnt/finished_fotograf
done
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top