You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

按首字母筛选顶层目录复制至服务器的脚本问题求助

Solution to Copy Only Top-Level Directories Starting with "u"

Got it, let's fix this issue for you. The root problem with your current script is that it isn't restricting its match to only top-level directories—it's recursively picking up any subdirectory that starts with "u" too, which is causing those duplicate copies. Here are two straightforward, reliable approaches to fix this:

rsync is perfect for this kind of selective directory copy because it lets you explicitly include/exclude items with precision. Run this command:

rsync -av --include='u*/' --exclude='*' /your/workstation/source/path/ /your/server/destination/path/

Let's break down what each part does:

  • -av: Enables archive mode (preserves permissions, timestamps, etc.) and verbose output so you can see what's being copied.
  • --include='u*/': Tells rsync to only include top-level directories that start with "u" (the trailing / ensures we only match directories, not files).
  • --exclude='*': Excludes everything else, which prevents any recursive matching of subdirectories.

Method 2: Use find + cp

If you prefer using basic Unix tools, find can target only top-level directories and pass them to cp:

find /your/workstation/source/path -maxdepth 1 -type d -name 'u*' -exec cp -r {} /your/server/destination/path/ \;

Here's the breakdown:

  • -maxdepth 1: Restricts find to only look at the top level of the source directory (no subdirectories).
  • -type d: Ensures we only match directories, not files.
  • -name 'u*': Filters for directories starting with "u".
  • -exec cp -r {} ...: Copies each matching directory recursively to your server destination.

Just make sure to replace /your/workstation/source/path and /your/server/destination/path with your actual directory paths. Both methods will avoid copying those unwanted nested "u" subdirectories and only grab the top-level ones you need.

内容的提问来源于stack exchange,提问作者Jonathan Becker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:56:24