将53,800多个文件移动到54个单独的文件夹中,每个文件约1000个文件?

尝试使用Gmail的POP提取器导入53,800多个单独的文件(消息)。

Gmail可以理解地拒绝,给出错误: “太多的邮件下载。在另一台服务器上有太多的消息。

有问题的文件夹看起来像是类似于:

/usr/home/customer/Maildir/cur/1203672790.V57I586f04M867101.mail.net:2,S /usr/home/customer/Maildir/cur/1203676329.V57I586f22M520117.mail.net:2,S /usr/home/customer/Maildir/cur/1203677194.V57I586f26M688004.mail.net:2,S /usr/home/customer/Maildir/cur/1203679158.V57I586f2bM182864.mail.net:2,S /usr/home/customer/Maildir/cur/1203680493.V57I586f33M740378.mail.net:2,S /usr/home/customer/Maildir/cur/1203685837.V57I586f0bM835200.mail.net:2,S /usr/home/customer/Maildir/cur/1203687920.V57I586f65M995884.mail.net:2,S ... 

在FreeBSD上使用shell(tcsh,sh等),我可以input什么单行命令来将这个充满文件的目录分割成单独的文件夹,这样Gmail一次只能看到1000条消息? 与find或ls |的东西 xargs mv也许。 无论最快。

所需的输出目录现在看起来像这样:

 /usr/home/customer/Maildir/cur/1203672790.V57I586f04M867101.mail.net:2,S /usr/home/customer/Maildir/cur/1203676329.V57I586f22M520117.mail.net:2,S ... /usr/home/customer/set1/ (contains messages 1-1000) /usr/home/customer/set2/ (contains messages 1001-2000) /usr/home/customer/set3/ (etc.) 

这不是一个单行的,但你可以像这样复制块(在csh中):

 foreach file (`ls | head -n 1000`) mv $file /tmp/new/dir end 

我并不是100%确定pipe道能够处理你拥有的文件数量,但是值得一试。 另外,你也许可以用这个命令一次完成500个,只需要把1000改成500。

 count=target=0; find srcdir/ -type f | while read file; do count=$((count+1)); target=$((count/10000)); [ -d $target ] || mkdir $target echo mv "$file" $target; #remove the 'echo' if you like what you see done 

折叠成一行(并删除了“回声”保护):

 count=target=0; find srcdir/ -type f | while read file; do count=$((count+1)); target=$((count/10000)); [ -d $target ] || mkdir $target; mv "$file" $target; done 

这不是最快的,但干净。 这个解决scheme避免parsing'ls'的输出http://mywiki.wooledge.org/ParsingLs并引用“$ file”的引用,否则具有exception名称的文件(如Maildir文件通常会)会破坏代码。 例如,如果任何文件都有空格或分号,那么引用不带引号的$ file文件不会让你感到困惑(大部分时间)

阅读更多关于引用: http : //mywiki.wooledge.org/Quotes和http://wiki.bash-hackers.org/syntax/words