picoCTF First Grep Writeup: Find the Flag with grep

Misc 2026-10-08 · Updated 2026-11-21 · picoGym · By CTFdojo · ⏱ ... · 👁 ... views
𝕏 Share
TL;DR

A large text file containing a huge amount of noise lines is provided. The grep command lets us search directly for the pattern picoCTF{ across all this content in a single command, without having to read the file manually.

PlatformpicoGym
Verified againsttcode2k16's picoCTF 2019 writeup
CategoryGeneral Skills / Misc
Points50 pts
DifficultyBeginner
TechniqueText search with grep

Challenge description

The challenge (picoCTF 2019) provides a single text file named simply file, full of random-looking text. The challenge's name — "First Grep" — clearly hints at the tool expected to solve it.

Stuck? Try a hint before reading the solution

Hint 1

The file is too big to read; search it instead.

Hint 2

grep picoCTF file.

Step 1 — Observe the problem

We download and open the file in a text editor to get a sense of it:

$ cat file

The terminal fills with a wall of random characters. Scanning it by eye to spot one specific string is impractical. We need a search tool.

Step 2 — Use grep

The grep command (Global Regular Expression Print) searches for a pattern in a text file and only displays the lines that contain it. We search directly for the characteristic prefix of all picoCTF flags:

$ grep "picoCTF{" file

The command returns the matching line, which contains the flag:

picoCTF{***************************}

Step 3 — The case of a whole folder

This challenge only has one file, but later ones (like First Grep: Part II) spread the flag across many files in subfolders. The -r (recursive) option applies the same search to the entire tree:

$ grep -r "picoCTF{" .
./some/sub/folder/file:picoCTF{***************************}

This option is extremely useful outside of CTFs too — for example to quickly find a string across an entire codebase or a folder of logs.

Useful variants

A few grep options that come up constantly:

$ grep -o "picoCTF{[^}]*}" file
picoCTF{***************************}
🚩 picoCTF{flag intentionally hidden}

The flag is deliberately hidden — follow the method, you've earned it. 💪

Key takeaways

grep is probably the most used tool day-to-day in CTFs as well as system administration. Knowing how to search for a precise pattern in a large volume of text — logs, memory dumps, source code, network captures — is a non-negotiable base skill.

Resources

CTFdojo
CTFdojo
Community of ethical hackers writing beginner-friendly CTF writeups and guides.

Got a question or a different approach?

Discuss this writeup with the community on the CTFdojo Discord.

Join the Discord →