ugrep

ugrep

高效全能的开源文件搜索工具

ugrep是一款开源的高性能文件搜索工具,支持Unicode和多行匹配。它能搜索压缩文件和PDF等文档,提供交互式TUI界面和类Google的布尔查询。ugrep完全兼容GNU grep,并增加了模糊搜索、二进制文件搜索等新功能。其高效的DFA正则表达式引擎保证了快速的搜索速度。ugrep支持JSON、XML等多种输出格式,是一个功能全面的现代grep替代工具。

ugrep文本搜索正则表达式命令行工具开源软件Github开源项目
<p align="center"> <a href="https://github.com/Genivia/ugrep/actions/workflows/c-cpp.yml"><img src="https://github.com/Genivia/ugrep/actions/workflows/c-cpp.yml/badge.svg"></a> <a href="https://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/license-BSD%203--Clause-blue.svg"></a> </p> <h1 align="center">The ugrep file pattern searcher</h1> <p align="center"> [ <b>README</b> | <a href="https://ugrep.com">User&nbsp;Guide</a> | <a href="https://github.com/Genivia/ugrep-indexer">Indexing</a> | <a href="https://github.com/Genivia/ugrep-benchmarks">Benchmarks</a> | <a href="https://github.com/Genivia/ugrep/discussions/categories/q-a">Q&amp;A</a> ] <br> <br> <img src="https://www.genivia.com/images/scranim.gif" width="438" alt=""> <br> <i>option -Q opens a query TUI to search files as you type!</i> </p>

Why use ugrep?

  • ugrep is fast, user-friendly, and equipped with a ton of new features that users wanted

  • includes an interactive TUI with built-in help, Google-like search with AND/OR/NOT patterns, fuzzy search, searches (nested) zip/7z/tar/pax/cpio archives, tarballs and compressed files gz/Z/bz/bz2/lzma/xz/lz4/zstd/brotli, search and hexdump binary files, search documents such as PDF, doc, docx, and output in JSON, XML, CSV or your own customized format

  • Unicode extended regex pattern syntax with multi-line pattern matching without requiring special command-line options

  • includes a file indexer to speed up searching slow and cold file systems

  • a true drop-in replacement for GNU grep (assuming you copy or symlink ug to grep, and to egrep and to fgrep), unlike other popular grep claiming to be "grep alternatives" or "replacements" when those actually implement incompatible command-line options and use an incompatible regex matcher, i.e. Perl regex only versus POSIX BRE (grep) and ERE (egrep) when ugrep supports all regex modes

  • benchmarks show that ugrep is (one of) the fastest grep using the high-performance DFA-based regex matcher RE/flex

Development roadmap

if something should be improved or added to ugrep, then let me know!

Overview

Commands

  • ug is for interactive use, which loads an optional .ugrep configuration file with your preferences located in the working directory or home directory, ug+ also searches pdfs, documents, e-books, image metadata

  • ugrep for batch use like GNU grep without a .ugrep configuration file, ugrep+ also searches pdfs, documents, e-books, image metadata

What does ugrep add that GNU grep does not support?

  • Matches Unicode patterns by default and automatically searches UTF-8, UTF-16 and UTF-32 encoded files

  • Matches multiple lines with \n or \R in regex patterns, no special options are required to do so!

  • Built-in help: ug --help, where ug --help WHAT displays options related to WHAT you are looking for

    💡 ug --help regex, ug --help globs, ug --help fuzzy, ug --help format.

  • User-friendly with customizable configuration files used by the ug command intended for interactive use that loads a .ugrep configuration file with your preferences

    ug PATTERN ...                         ugrep --config PATTERN ...
    

    💡 ug --save-config ...options-you-want-to-save... saves a .ugrep config file in the working directory so that the next time you run ug there it uses these options. Do this in your home directory to save a .ugrep config file with options you generally want to use.

  • Interactive query TUI, press F1 or CTRL-Z for help and TAB/SHIFT-TAB to navigate to dirs and files

    ug -Q                                  ug -Q -e PATTERN
    

    💡 -Q replaces PATTERN on the command line to let you enter patterns interactively in the TUI. In the TUI use ALT+letter keys to toggle short "letter options" on/off, for example ALT-n (option -n) to show/hide line numbers.

  • Search the contents of archives (zip, tar, pax, jar, cpio, 7z) and compressed files (gz, Z, bz, bz2, lzma, xz, lz4, zstd, brotli)

    ug -z PATTERN ...                      ug -z --zmax=2 PATTERN ...
    

    💡 specify -z --zmax=2 to search compressed files and archives nested within archives. The --zmax argument may range from 1 (default) to 99 for up to 99 decompression and de-archiving steps to search nested archives

  • Search with Google-like Boolean query patterns using -% patterns with AND (or just space), OR (or a bar |), NOT (or a dash -), using quotes to match exactly, and grouping with ( ) (shown on the left side below); or with options -e (as an "or"), --and, --andnot, and --not regex patterns (shown on the right side below):

    ug -% 'A B C' ...                      ug -e 'A' --and 'B' --and 'C' ...
    ug -% 'A|B C' ...                      ug -e 'A' -e 'B' --and 'C' ...
    ug -% 'A -B -C' ...                    ug -e 'A' --andnot 'B' --andnot 'C' ...
    ug -% 'A -(B|C)'...                    ug -e 'A' --andnot 'B' --andnot 'C' ...
    ug -% '"abc" "def"' ...                ug -e '\Qabc\E' --and '\Qdef\E' ...
    

    where A, B and C are arbitrary regex patterns (use option -F to search strings)

    💡 specify option -%% (--bool --files) to apply the Boolean query to files as a whole: a file matches if all Boolean conditions are satisfied by matching patterns file-wide. Otherwise, Boolean conditions apply to single lines by default, since grep utilities are generally line-based pattern matchers. Option --stats displays the query in human-readable form after the search completes.

  • Search pdf, doc, docx, e-book, and more with ug+ using filters associated with filename extensions:

    ug+ PATTERN ...
    

    or specify --filter with a file type to use a filter utility:

    ug --filter='pdf:pdftotext % -' PATTERN ...
    ug --filter='doc:antiword %' PATTERN ...
    ug --filter='odt,docx,epub,rtf:pandoc --wrap=preserve -t plain % -o -' PATTERN ...
    ug --filter='odt,doc,docx,rtf,xls,xlsx,ppt,pptx:soffice --headless --cat %' PATTERN ...
    ug --filter='pem:openssl x509 -text,cer,crt,der:openssl x509 -text -inform der' PATTERN ...
    ug --filter='latin1:iconv -f LATIN1 -t UTF-8' PATTERN ...
    

    💡 the ug+ command is the same as the ug command, but also uses filters to search PDFs, documents, and image metadata

  • Display horizontal context with option -o (--only-matching) and context options -ABC, e.g. to find matches in very long lines, such as Javascript and JSON sources:

    ug -o -C20 -nk PATTERN longlines.js
    

    💡 -o -C20 fits all matches with context in 20 characters before and 20 charactess after a match (i.e. 40 Unicode characters total), -nk outputs line and column numbers.

  • Find approximate pattern matches with fuzzy search, within the specified Levenshtein distance

    ug -Z PATTERN ...                      ug -Z3 PATTTERN ...
    

    💡 -Zn matches up to n extra, missing or replaced characters, -Z+n matches up to n extra characters, -Z-n matches with up to n missing characters and -Z~n matches up to n replaced characters. -Z defaults to -Z1.

  • Fzf-like search with regex (or fixed strings with -F), fuzzy matching with up to 4 extra characters with -Z+4 and words only with -w, using -%% for file-wide Boolean searches

    ug -Q -%% -l -w -Z+4 --sort=best
    

    💡 -l lists the matching files in the TUI, press TAB then ALT-y to view a file, SHIFT-TAB and Alt-l to go back to view the list of matching files ordered by best match

  • Search binary files and display hexdumps with binary pattern matches (Unicode text or -U for byte patterns)

    ug --hexdump -U BYTEPATTERN ...        ug --hexdump TEXTPATTERN ...
    ug -X -U BYTEPATTERN ...               ug -X TEXTPATTERN ...
    ug -W -U BYTEPATTERN ...               ug -W TEXTPATTERN ...
    

    💡 --hexdump=4chC1 displays 4 columns of hex without a character column c, no hex spacing h, and with one extra hex line C1 before and after a match.

  • Include files to search by file types or file "magic bytes" or exclude them with ^

    ug -t TYPE PATTERN ...                 ug -t ^TYPE PATTERN ...
    ug -M 'MAGIC' PATTERN ...              ug -M '^MAGIC' PATTERN ...
    
  • Include files and directories to search that match gitignore-style globs or exclude them with ^

    ug -g 'FILEGLOB' PATTERN ...           ug -g '^FILEGLOB' PATTERN ...
    ug -g 'DIRGLOB/' PATTERN ...           ug -g '^DIRGLOB/' PATTERN ...
    ug -g 'PATH/FILEGLOB' PATTERN ...      ug -g '^PATH/FILEGLOB' PATTERN ...
    ug -g 'PATH/DIRGLOB/' PATTERN ...      ug -g '^PATH/DIRGLOB/' PATTERN ...
    
  • Include files to search by filename extensions (suffix) or exclude them with ^, a shorthand for -g"*.EXT"

    ug -O EXT PATTERN ...                  ug -O ^EXT PATTERN ...
    
  • Include hidden files (dotfiles) and directories to search (omitted by default)

    ug -. PATTERN ...                      ug -g'.*,.*/' PATTERN ...
    

    💡 specify hidden in your .ugrep to always search hidden files with ug.

  • Exclude files specified by .gitignore etc.

    ug --ignore-files PATTERN ...          ug --ignore-files=.ignore PATTERN ...
    

    💡 specify ignore-files in your .ugrep to always ignore them with ug. Add additional ignore-files=... as desired.

  • Search patterns excluding negative patterns ("match this but not that")

    ug -e PATTERN -N NOTPATTERN ...        ug -e '[0-9]+' -N 123 ...
    
  • Use predefined regex patterns to search source code, javascript, XML, JSON, HTML, PHP, markdown, etc.

    ug PATTERN -f c++/zap_comments -f c++/zap_strings ...
    ug PATTERN -f php/zap_html ...
    ug -f js/functions ... | ug PATTERN ...
    
  • Sort matching files by name, best match, size, and time

    ug --sort PATTERN ...                  ug --sort=size PATTERN ...
    ug --sort=changed PATTERN ...          ug --sort=created PATTERN ...
    ug -Z --sort=best PATTERN ...          ug --no-sort PATTERN ...
    
  • Output results in CSV, JSON, XML, and user-specified formats

    ug --csv PATTERN ...                   ug --json PATTERN ...
    ug --xml PATTERN ...                   ug --format='file=%f line=%n match=%O%~' PATTERN ...
    

    💡 ug --help format displays help on format % fields for customized output.

  • Search with PCRE's Perl-compatible regex patterns and display or replace subpattern matches

    ug -P PATTERN ...                      ug -P --format='%1 and %2%~' 'PATTERN(SUB1)(SUB2)' ...
    
  • Replace patterns in the output with -P and --replace replacement text, optionally containing % formatting fields, using -y to pass the rest of the file through:

    ug --replace='TEXT' PATTERN ...        ug -y --replace='TEXT' PATTERN ...
    ug --replace='(%m:%o)' PATTERN ...     ug -y --replace='(%m:%o)' PATTERN ...
    ug -P --replace='%1' PATTERN ...       ug -y -P --replace='%1' PATTERN ...
    

    💡 ug --help format displays help on format % fields to optionally use with --replace.

  • Search files with a specific encoding format such as ISO-8859-1 thru 16, CP 437, CP 850, MACROMAN, KOI8, etc.

    ug --encoding=LATIN1 PATTERN ...
    
<a name="toc"/>

Table of contents

编辑推荐精选

TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

热门AI工具生产力协作转型TraeAI IDE
蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI助手AI工具AI写作工具AI辅助写作蛙蛙写作学术助手办公助手营销助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

聊天机器人AI助手热门AI工具AI对话
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

热门AI工具AI办公办公工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

模型训练热门AI工具内容创作智能问答AI开发讯飞星火大模型多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

AI助手热门AI工具AI创作AI辅助写作讯飞绘文内容运营个性化文章多平台分发
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多