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

如何在Unix Solaris全文件系统中提取含任意邮箱的文件列表

Alright, let's sort this out for your Solaris system. You've been using a command to hunt down files with emails from a specific domain, but now you need to expand that to catch any valid email address instead. Here's how to adjust your approach properly:

Matching Any Email Address Across the Solaris Filesystem

First, a quick note on your original command: the regex /*@ isn't valid syntax (you probably meant .*@ to match any characters before the @ symbol). But to match standard emails of any domain, we'll need a more robust regex, plus tweaks to work smoothly with Solaris's tools.

Option 1: Use find with -exec (Most Efficient)

This approach avoids potential issues with filenames containing spaces and is generally more efficient than piping to xargs:

find / -type f -exec grep -lE "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}" {} + 2>/dev/null

Let's break this down:

  • find / -type f: Scans the entire root filesystem for regular files (skips directories, symlinks, and special files like device nodes)
  • -exec grep -lE ... {} +: Passes batches of found files to grep (the + means it groups files instead of running grep once per file)
  • -l: Makes grep output only the filenames that contain a match, not the matching lines
  • -E: Enables extended regular expressions (ERE) for a cleaner, more readable email pattern
  • The regex [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}:
    • [A-Za-z0-9._%+-]+: Matches the local part of the email (before @) — covers all standard valid characters
    • @: The mandatory separator between local and domain parts
    • [A-Za-z0-9.-]+: Matches the main domain name (e.g., example in example.com)
    • \.[A-Za-z]{2,}: Matches the top-level domain (e.g., .com, .org, .co.uk) requiring at least 2 characters
  • 2>/dev/null: Suppresses permission-denied errors when accessing restricted system directories like /proc or /dev

Option 2: Stick with xargs (If You Prefer)

If you want to keep using xargs, add -print0 to find and -0 to xargs to handle filenames with spaces or special characters:

find / -type f -print0 | xargs -0 grep -lE "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}" 2>/dev/null

Solaris-Specific Notes

  • If your Solaris version doesn't support grep -E, replace it with egrep (it's the equivalent tool for extended regex on older Solaris systems):
    find / -type f -exec egrep -l "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}" {} + 2>/dev/null
    
  • If you don't need to scan the entire filesystem, replace / with your target path (e.g., /opt/myuser/V9/server/instance1/default/packs*) like you did in your example.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:23:04