Chuyển đến nội dung
Skillpedia
Lập trình chung7.8k · #13040

combined-head-linecount-check

Skill này làm gì

Skill này chỉ cho AI agent cách xem đầu một file và đếm số dòng của nó trong một lệnh. Nó dành cho những người muốn kiểm tra nhanh các file mã hoặc cấu hình.

Khi nào nên dùng

  • ✓Khi bạn muốn xem vài dòng đầu của một file và file dài bao nhiêu trong một bước.
  • ✓Khi bạn đang kiểm tra nhiều file và muốn ít lệnh shell hơn.
  • ✓Khi nội dung đầu file hoặc độ dài của nó quan trọng trước khi bạn sửa.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/combined-head-linecount-check/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/combined-head-linecount-check/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Cho tôi xem 10 dòng đầu của main.ts và nó có bao nhiêu dòng, trong một lần kiểm tra.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent chạy head để hiện các dòng đầu, in một đường phân cách, rồi chạy wc -l để đếm số dòng. Đầu ra hiện nội dung trước, còn số dòng nằm dưới đường gạch ngang.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Combined Head + Line Count Check

When you need to both inspect the top of a file and confirm its total line count, collapse the two checks into a single run_shell call instead of issuing two separate commands.

Why

  • Each shell call is a round-trip. Two separate calls (head then wc -l) cost two iterations.
  • A combined call costs one iteration and returns both pieces of information atomically.
  • When checking multiple files at once, each file still only needs one call (or all files can be parallelized in a single compound command).

Pattern

head -N <file> && echo "---" && wc -l <file>

The echo "---" separator makes the output easy to parse visually: everything above the dashes is content, everything below is the line count.

Examples

Single file — inspect first 10 lines and total count

head -10 src/main.ts && echo "---" && wc -l src/main.ts

Sample output:

import { createApp } from 'vue'
import App from './App.vue'
...
---
      142 src/main.ts

Multiple files — fully parallelized

When you need to check several files simultaneously, run them all in one shell call using && chains or newline-separated subshells:

(head -10 src/main.ts     && echo "---" && wc -l src/main.ts)     && echo "===" && \
(head -10 vite.config.ts  && echo "---" && wc -l vite.config.ts)  && echo "===" && \
(head -5  package.json    && echo "---" && wc -l package.json)

Or, if order independence is acceptable, run them in parallel background jobs and wait:

{
  head -10 src/main.ts    && echo "---" && wc -l src/main.ts
} &
{
  head -10 vite.config.ts && echo "---" && wc -l vite.config.ts
} &
wait

When to Apply

Situation Recommendation
Verifying a generated/modified file was written correctly ✅ Use combined call
Checking multiple output files after a build step ✅ Parallelize all in one shell call
Only need line count (no content preview required) Use plain wc -l
Only need content (no line count required) Use plain head -N
File is extremely large and you want a middle section Use sed -n or awk instead

Integration with Parallel Reads

This pattern compounds well with parallel file reads. In a single iteration you can:

  1. Read file contents with cat or head for multiple files.
  2. Simultaneously verify line counts with wc -l.
  3. Check for specific patterns with grep -c.

Example of a 5-file parallel verification in one shell call:

echo "=== main.ts ===" && head -10 src/main.ts && echo "lines:" && wc -l < src/main.ts && \
echo "=== config ===" && head -5 vite.config.ts && echo "lines:" && wc -l < vite.config.ts && \
echo "=== package ===" && head -5 package.json && echo "lines:" && wc -l < package.json && \
echo "=== index ===" && head -8 index.html && echo "lines:" && wc -l < index.html && \
echo "=== readme ===" && head -5 README.md && echo "lines:" && wc -l < README.md

Tip: Using wc -l < file (with input redirect) prints only the number, without the filename — cleaner output when the filename is already shown by the echo label above it.

Key Takeaway

Never use two shell calls where one will do. Combining head -N and wc -l in a single command is the minimal-overhead way to answer both "what does this file contain?" and "is it the right size?" simultaneously.

Câu hỏi thường gặp

Tại sao kết hợp hai kiểm tra?

Mỗi lệnh shell tốn một vòng gọi đi về, nên một lệnh kết hợp hoàn thành công việc trong ít bước hơn.

Nó có kiểm tra nhiều file cùng lúc được không?

Có, skill chỉ cách nối các kiểm tra cho nhiều file trong một lệnh shell.

Đường gạch ngang dùng để làm gì?

Nó tách nội dung file khỏi số dòng, giúp đầu ra dễ đọc.

Chi tiết

Mô tả gốc của tác giả

Verify a file's first N lines and total line count in one shell call using head and wc -l with an echo separator, minimizing read operations and shell iterations.

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#13040
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự