AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 121623
Accepted
ane
ane
Asked: 2010-03-12 10:39:53 +0800 CST2010-03-12 10:39:53 +0800 CST 2010-03-12 10:39:53 +0800 CST

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

  • 772

尝试使用 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
...

使用 shell(FreeBSD 上的 tcsh、sh 等),我可以键入什么单行命令来将这个充满文件的目录拆分到单独的文件夹中,这样 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.)
maildir pop3 gmail
  • 2 2 个回答
  • 1016 Views

2 个回答

  • Voted
  1. Best Answer
    Chris S
    2010-03-12T11:15:44+08:002010-03-12T11:15:44+08:00

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

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

    我不能 100% 确定管道是否适用于您拥有的文件数量,但值得一试。此外,您可能可以使用此命令一次执行 500 次,只需将 1000 更改为 500 即可。

    • 4
  2. sente
    2010-06-17T00:11:28+08:002010-06-17T00:11:28+08:00
    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
    

    这不是最快的,但很干净。此解决方案避免解析 'ls' http://mywiki.wooledge.org/ParsingLs的输出并引用对“$file”的引用,否则具有异常名称的文件(如 Maildir 文件通常是)会破坏代码。例如,如果任何文件有空格或分号,那么引用 $file 不带引号不会让你走得太远(大多数时候)

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

    • 1

相关问题

  • Exim+SA 的 LDA

  • 在整个 Maildir 中解码 TNEF / winmail.dat

  • 无法发送到 Maildir:postfix

  • Maildir 文件夹存储的最佳文件系统是什么?[关闭]

  • 带有自定义路径的后缀 maildir

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve