logseq-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLogseq CLI
Logseq CLI
Overview
概述
Use to inspect and edit graph entities, run Datascript queries, and control graph/server lifecycle.
logseq使用来查看和编辑图谱实体、运行Datascript查询,以及控制图谱/服务器的生命周期。
logseqQuick start
快速开始
- Run to see top-level commands and global flags.
logseq --help - Run to see command-specific options.
logseq <command> --help - Use to target a specific graph.
--graph - Omit for human output. Set
--outputor--output jsononly when machine-readable output is required.--output edn
- 运行查看顶级命令和全局标志。
logseq --help - 运行查看命令专属选项。
logseq <command> --help - 使用指定目标图谱。
--graph - 省略将输出人类可读格式。仅当需要机器可读输出时,设置
--output或--output json。--output edn
Command groups (from logseq --help
)
logseq --help命令组(来自logseq --help
)
logseq --help- Graph inspect/edit:
- ,
list page,list taglist property - ,
upsert block,upsert page,upsert tagupsert property - ,
remove block,remove page,remove tagremove property - ,
query,query listshow - Graph management:
graph list|create|switch|remove|validate|info|export|import - Server management:
server list|status|start|stop|restart - Diagnostics:
doctor
- 图谱查看/编辑:
- ,
list page,list taglist property - ,
upsert block,upsert page,upsert tagupsert property - ,
remove block,remove page,remove tagremove property - ,
query,query listshow - 图谱管理:
graph list|create|switch|remove|validate|info|export|import - 服务器管理:
server list|status|start|stop|restart - 诊断:
doctor
Global options
全局选项
- Path to
--config(defaultcli.edn)~/logseq/cli.edn - Graph name
--graph - Path to db-worker data dir (default
--data-dir)~/logseq/graphs - Request timeout in ms (default
--timeout-ms)10000 - Output format (
--output,human,json)edn - Enable verbose debug logging to stderr
--verbose
--config的路径(默认cli.edn)~/logseq/cli.edn- 图谱名称
--graph - db-worker数据目录的路径(默认
--data-dir)~/logseq/graphs - 请求超时时间(毫秒,默认10000)
--timeout-ms - 输出格式(
--output,human,json)edn - 启用详细调试日志输出到stderr
--verbose
Command option policy
命令选项规则
- Do not memorize or hardcode command options in this skill.
- Before running any command, always check live options with:
logseq <command> --helplogseq <command> <subcommand> --help
- 不要在此技能中记忆或硬编码命令选项。
- 在运行任何命令前,务必通过以下方式查看实时选项:
logseq <command> --helplogseq <command> <subcommand> --help
Example prerequisites
示例前置条件
- Replace placeholder ids/uuids in examples (,
123,321) with real entities from the target graph.1111... - Use ,
logseq list ..., orlogseq show ...first to discover valid ids/uuids.logseq query ... - requires
logseq graph export; keep--fileconsistent with the export path.graph import --input
- 将示例中的占位符ID/UUID(如,
123,321)替换为目标图谱中的真实实体。1111... - 先使用,
logseq list ...或logseq show ...发现有效的ID/UUID。logseq query ... - 需要
logseq graph export参数;--file需与导出路径保持一致。graph import --input
Examples
示例
bash
undefinedbash
undefinedList pages (human output by default)
List pages (human output by default)
logseq list page --graph "my-graph" --limit 50 --sort updated-at --order desc
logseq list page --graph "my-graph" --limit 50 --sort updated-at --order desc
Include built-in tags/properties
Include built-in tags/properties
logseq list tag --graph "my-graph" --include-built-in --limit 20 --output json
logseq list property --graph "my-graph" --include-built-in --limit 20 --output json
logseq list tag --graph "my-graph" --include-built-in --limit 20 --output json
logseq list property --graph "my-graph" --include-built-in --limit 20 --output json
Query by built-in query name
Query by built-in query name
logseq query --graph "my-graph" --name "recent-updated" --inputs "[30]"
logseq query --graph "my-graph" --name "recent-updated" --inputs "[30]"
Query with ad-hoc Datascript EDN
Query with ad-hoc Datascript EDN
logseq query --graph "my-graph" --query "[:find [?p ...] :where [?p :block/name]]"
logseq query --graph "my-graph" --query "[:find [?p ...] :where [?p :block/name]]"
List available queries (built-ins + custom-queries from cli.edn)
List available queries (built-ins + custom-queries from cli.edn)
logseq query list --graph "my-graph" --output edn
logseq query list --graph "my-graph" --output edn
Show a page tree or a block
Show a page tree or a block
logseq show --graph "my-graph" --page "Meeting Notes" --level 2
logseq show --graph "my-graph" --id 123
logseq show --graph "my-graph" --id "[123,456,789]"
logseq show --graph "my-graph" --page "Meeting Notes" --level 2
logseq show --graph "my-graph" --id 123
logseq show --graph "my-graph" --id "[123,456,789]"
Upsert a page (create or update by --id)
Upsert a page (create or update by --id)
logseq upsert page --graph "my-graph" --page "Project X"
logseq upsert page --graph "my-graph" --id 999 --update-properties "{:logseq.property/description "Example"}"
logseq upsert page --graph "my-graph" --page "Project X"
logseq upsert page --graph "my-graph" --id 999 --update-properties "{:logseq.property/description "Example"}"
Upsert blocks
Upsert blocks
logseq upsert block --graph "my-graph" --target-page "Meeting Notes" --content "Discuss roadmap"
logseq upsert block --graph "my-graph" --target-page "Meeting Notes" --content "AI summary of the discussion" --update-tags '["AI-GENERATED"]'
logseq upsert block --graph "my-graph" --blocks "[{:block/title "A"} {:block/title "B"}]"
logseq upsert block --graph "my-graph" --id 123 --update-tags '["AI-GENERATED"]'
logseq upsert block --graph "my-graph" --id 123 --status done
logseq upsert block --graph "my-graph" --target-page "Meeting Notes" --content "Discuss roadmap"
logseq upsert block --graph "my-graph" --target-page "Meeting Notes" --content "AI summary of the discussion" --update-tags '["AI-GENERATED"]'
logseq upsert block --graph "my-graph" --blocks "[{:block/title "A"} {:block/title "B"}]"
logseq upsert block --graph "my-graph" --id 123 --update-tags '["AI-GENERATED"]'
logseq upsert block --graph "my-graph" --id 123 --status done
Ensure a tag exists before associating it with a block
Ensure a tag exists before associating it with a block
logseq upsert tag --graph "my-graph" --name "AI-GENERATED"
logseq upsert block --graph "my-graph" --target-page "Meeting Notes" --content "AI summary of the discussion" --update-tags '["AI-GENERATED"]'
logseq upsert tag --graph "my-graph" --name "AI-GENERATED"
logseq upsert block --graph "my-graph" --target-page "Meeting Notes" --content "AI summary of the discussion" --update-tags '["AI-GENERATED"]'
Upsert tag/property
Upsert tag/property
logseq upsert tag --graph "my-graph" --name "Project"
logseq upsert tag --graph "my-graph" --id 200 --name "Project Renamed"
logseq upsert property --graph "my-graph" --name "Effort" --type number --cardinality one
logseq upsert property --graph "my-graph" --id 321 --hide true
logseq upsert tag --graph "my-graph" --name "Project"
logseq upsert tag --graph "my-graph" --id 200 --name "Project Renamed"
logseq upsert property --graph "my-graph" --name "Effort" --type number --cardinality one
logseq upsert property --graph "my-graph" --id 321 --hide true
Remove entities
Remove entities
logseq remove block --graph "my-graph" --id "[123,456]"
logseq remove block --graph "my-graph" --uuid "11111111-1111-1111-1111-111111111111"
logseq remove page --graph "my-graph" --name "Old Page"
logseq remove tag --graph "my-graph" --name "Old Tag"
logseq remove property --graph "my-graph" --id 321
logseq remove block --graph "my-graph" --id "[123,456]"
logseq remove block --graph "my-graph" --uuid "11111111-1111-1111-1111-111111111111"
logseq remove page --graph "my-graph" --name "Old Page"
logseq remove tag --graph "my-graph" --name "Old Tag"
logseq remove property --graph "my-graph" --id 321
Graph and server commands
Graph and server commands
logseq graph create --graph "my-graph"
logseq graph list
logseq graph switch --graph "my-graph"
logseq graph info --graph "my-graph"
logseq graph export --graph "my-graph" --type edn --file /tmp/my-graph.edn
logseq graph import --graph "my-graph-import" --type edn --input /tmp/my-graph.edn
logseq server status --graph "my-graph"
logseq doctor
undefinedlogseq graph create --graph "my-graph"
logseq graph list
logseq graph switch --graph "my-graph"
logseq graph info --graph "my-graph"
logseq graph export --graph "my-graph" --type edn --file /tmp/my-graph.edn
logseq graph import --graph "my-graph-import" --type edn --input /tmp/my-graph.edn
logseq server status --graph "my-graph"
logseq doctor
undefinedTag association semantics
标签关联语义
- For block or page tag association, prefer explicit CLI tag options such as and
--update-tags.--remove-tags - Do not treat writing inside
#TagNameas equivalent guidance to explicit tag association.--content - supports
upsert blockin both create mode and update mode.--update-tags - expects an EDN vector.
--update-tags - Tag values may be tag title/name strings, db/id, UUID, or values.
:db/ident - String tag values may include a leading , but they should still be passed inside
#rather than embedded in content as a substitute for association.--update-tags - If the user asks to tag a block or page, prefer explicit tag association over embedding hashtags in content.
- Tags must already exist and be public. If needed, create the tag first with .
upsert tag --name "<TagName>"
- 对于块或页面的标签关联,优先使用明确的CLI标签选项,如和
--update-tags。--remove-tags - 不要将在中写入
--content视为与明确标签关联等效的指引。#TagName - 在创建模式和更新模式下均支持
upsert block。--update-tags - 期望接收一个EDN向量。
--update-tags - 标签值可以是标签标题/名称字符串、db/id、UUID或值。
:db/ident - 字符串类型的标签值可以包含前缀,但仍应通过
#传递,而非嵌入到内容中作为关联的替代方式。--update-tags - 如果用户要求为块或页面添加标签,优先使用明确的标签关联,而非在内容中嵌入话题标签。
- 标签必须已存在且为公开状态。如有需要,先使用创建标签。
upsert tag --name "<TagName>"
Pitfalls
注意事项
- is not the same guidance as
--content "Summary #AI-GENERATED".--update-tags '["AI-GENERATED"]' - Do not pass as a comma-separated string. Use an EDN vector.
--update-tags - Do not assume a hashtag in block text will replace the need for explicit tag association when the user asks for a tagged block.
- If tag association fails, verify the tag exists and is public before retrying.
- 与
--content "Summary #AI-GENERATED"的作用并不相同。--update-tags '["AI-GENERATED"]' - 不要将作为逗号分隔的字符串传递,应使用EDN向量。
--update-tags - 当用户要求添加标签的块时,不要假设块文本中的话题标签可以替代明确的标签关联。
- 如果标签关联失败,请先验证标签是否存在且为公开状态,然后再重试。
Tips
提示
- returns both built-ins and
query listfromcustom-queries.cli.edn - accepts either one db/id or an EDN vector of ids.
show --id - also accepts one db/id or an EDN vector.
remove block --id - enters update mode when
upsert blockor--idis provided.--uuid - Always verify command flags with and
logseq --helpbefore execution.logseq <...> --help - If reports that it doesn’t have read/write permission for data-dir, then add read/write permission for data-dir in the agent’s config.
logseq - In sandboxed environments, may print a process-scan warning to stderr; if command status is
graph create, the graph is still created.ok
- 返回内置查询和
query list中的cli.edn。custom-queries - 支持单个db/id或EDN格式的ID向量。
show --id - 也支持单个db/id或EDN格式的ID向量。
remove block --id - 当提供或
--id时,--uuid进入更新模式。upsert block - 执行命令前务必通过和
logseq --help验证命令标志。logseq <...> --help - 如果报告没有数据目录的读写权限,在agent配置中为数据目录添加读写权限。
logseq - 在沙箱环境中,可能会向stderr打印进程扫描警告;如果命令状态为
graph create,则图谱已成功创建。ok
References
参考资料
- Built-in tags and properties: See when you need canonical built-ins for
references/logseq-builtins.mdor for tag/property upsert fields.list ... --include-built-in
- 内置标签和属性:当需要的标准内置项或标签/属性更新字段时,请查看
list ... --include-built-in。references/logseq-builtins.md