Bat
A lightweight, multi-purpose command-line utility for logging, searching, and managing text entries. All data stays local in plain-text log files — no cloud, no dependencies.
Commands
| Command | Description |
|---|
| INLINECODE0 | Execute the main function — prints the argument and logs the action. |
| INLINECODE1 |
Show the config file path (
$DATA_DIR/config.json) and log the action. |
|
status | Print current status ("ready") and log the check. |
|
init | Initialize the data directory — confirms creation at
$DATA_DIR. |
|
list | Print all entries from the main data log (
data.log). Shows "(empty)" if no entries exist. |
|
add <text> | Append a timestamped entry to the log. Format:
YYYY-MM-DD <text>. |
|
remove <text> | Mark an entry as removed and log the removal action. |
|
search <term> | Case-insensitive search through all logged entries. Shows "Not found" if no matches. |
|
export | Output the full data log to stdout. Pipe to a file for backups:
bat export > backup.txt. |
|
info | Show version number and data directory path. |
|
help | Show full usage information with all available commands. |
|
version | Print version number (
v2.0.2). |
Data Storage
All data is stored in ~/.local/share/bat/ by default:
- -
data.log — Main log file (one entry per line, date-prefixed via add) - INLINECODE21 — Command history with timestamps (auto-maintained by every command)
- INLINECODE22 — Configuration file path (shown by
bat config)
Set the BAT_DIR environment variable to change the storage location. Alternatively, XDG_DATA_HOME is respected if BAT_DIR is not set.
Requirements
- - Bash 4+ (uses
local variables, set -euo pipefail) - Standard Unix utilities (
grep, date, wc, cat) - No external dependencies or API keys required
When to Use
- 1. Quick note-taking from the terminal — Use
bat add to jot down thoughts, meeting notes, or TODO items without leaving the shell. - Maintaining a running activity log — Every
add creates a dated entry, building a chronological record of activities over time. - Searching past entries by keyword — Use
bat search <term> to find specific entries with case-insensitive matching. - Exporting and backing up notes — Use
bat export > backup.txt to dump all entries for backup, sharing, or migration. - General-purpose CLI data management — Use
run, init, config, and status as building blocks for scripted workflows and automation pipelines.
Examples
CODEBLOCK0
Output
All commands print results to stdout and log actions to history.log. The add command confirms each save with the added text. The list and export commands output raw log content suitable for piping and redirection.
Powered by BytesAgain | bytesagain.com | hello@bytesagain.com
Bat
一款轻量级、多用途的命令行工具,用于记录、搜索和管理文本条目。所有数据均保存在本地的纯文本日志文件中——无需云服务,无依赖项。
命令
| 命令 | 描述 |
|---|
| run <参数> | 执行主要功能——打印参数并记录操作。 |
| config |
显示配置文件路径($DATA_DIR/config.json)并记录操作。 |
| status | 打印当前状态(ready)并记录检查操作。 |
| init | 初始化数据目录——确认在$DATA_DIR创建目录。 |
| list | 打印主数据日志(data.log)中的所有条目。若无条目则显示(empty)。 |
| add <文本> | 向日志追加带时间戳的条目。格式:YYYY-MM-DD <文本>。 |
| remove <文本> | 将条目标记为已删除并记录删除操作。 |
| search <关键词> | 在所有记录的条目中进行不区分大小写的搜索。若无匹配则显示Not found。 |
| export | 将完整数据日志输出到标准输出。可通过管道备份到文件:bat export > backup.txt。 |
| info | 显示版本号和数据目录路径。 |
| help | 显示包含所有可用命令的完整使用信息。 |
| version | 打印版本号(v2.0.2)。 |
数据存储
默认情况下,所有数据存储在~/.local/share/bat/目录中:
- - data.log — 主日志文件(每行一个条目,通过add命令添加日期前缀)
- history.log — 带时间戳的命令历史记录(由每条命令自动维护)
- config.json — 配置文件路径(通过bat config显示)
设置BATDIR环境变量可更改存储位置。若未设置BATDIR,则会遵循XDGDATAHOME。
系统要求
- - Bash 4+(使用local变量、set -euo pipefail)
- 标准Unix工具(grep、date、wc、cat)
- 无需外部依赖或API密钥
使用场景
- 1. 终端快速笔记 — 使用bat add记录想法、会议笔记或待办事项,无需离开shell。
- 维护活动日志 — 每次add都会创建带日期的条目,逐步构建按时间顺序的活动记录。
- 按关键词搜索历史条目 — 使用bat search <关键词>进行不区分大小写的匹配搜索。
- 导出和备份笔记 — 使用bat export > backup.txt导出所有条目用于备份、分享或迁移。
- 通用CLI数据管理 — 将run、init、config和status作为脚本化工作流和自动化管道的构建模块。
示例
bash
添加关于会议的笔记
bat add 与客户讨论Q2目标
添加另一条条目
bat add 向供应商发送了跟进邮件
列出所有记录的条目
bat list
搜索提及client的条目
bat search client
将日志导出到备份文件
bat export > ~/bat-backup.txt
检查版本和数据目录
bat info
初始化(或验证)数据目录
bat init
检查运行状态
bat status
显示配置文件路径
bat config
输出
所有命令将结果打印到标准输出,并将操作记录到history.log。add命令会通过显示添加的文本确认每次保存。list和export命令输出适合管道和重定向的原始日志内容。
由BytesAgain提供技术支持 | bytesagain.com | hello@bytesagain.com