THE FUTURE MARKETACADEMY
Your classroomRoom 07 · Tech Lab
School of Data & Tech

Command Line 2: files, search, pipes and scripts

Step 6 of 8 in Tech Lab

Next in your path: 7.5.2 Python for Data: files, libraries and automation

What you'll be able to do
  • Use wildcards to pick many files at once, and know who expands them (the shell or the program).
  • Find files by name or type with find (Mac/Linux) and Get-ChildItem (PowerShell).
  • Search inside files with grep and Select-String.
  • Chain commands with pipes and save results with redirection (>, >>, 2>).
  • Read and set environment variables, and understand PATH.
  • Write, test and run a first script safely, with a "preview first" mode.
  • Build a script that organises a messy folder without deleting anything.

Before this course: Command Line Basics (course 7.11). You should already be able to open a terminal, use pwd, cd and ls, make, copy and move files, and explain why you never paste a command you do not understand. Everything here still happens in a practice folder.

Set up once: make a practice folder called sandbox and put a few files in it, for example notes.txt (type a few lines, one containing the word apple), a1.txt, a2.txt, b1.txt, photo1.jpg, photo2.jpg and a small sub-folder sub. Never run these exercises on folders that hold your only copy of important files.

Words in this course 35Open the Vocabulary Hall
01

Wildcards: pick many files at once

In simple words

Instead of naming every toy one by one, you can say "all the red ones". A wildcard is a special character that stands for "anything", so one short command can work on lots of files.

Key facts
  • Before this course: Command Line Basics (course 7.11). There you typed one file name at a time. Wildcards let you match many names with one pattern.
  • On Mac and Linux the common wildcards are * (any number of characters, including none), ? (exactly one character) and [ab] or [0-9] (one character from a set or range).
  • On Mac and Linux it is the shell, not the program, that expands the pattern, per the Bash manual (it calls this filename or pathname expansion). So ls *.txt becomes ls a1.txt a2.txt notes.txt before ls even runs.
  • In PowerShell, wildcard matching is done by the cmdlet receiving the pattern, per Microsoft's wildcard help. Get-ChildItem *.txt works the same way for you as a user.
  • Quotes matter. A file name with a space, such as my file.txt, must be quoted: ls "my file.txt". Without quotes the shell sees two names.
  • A wildcard cannot see inside files; it only matches names. Hidden files (names starting with a dot) are normally not matched by * in Bash and zsh.
  • Safety: a wildcard multiplies a command. rm .txt deletes every match. Always run ls .txt first to see what the pattern matches, then change ls to the real command, and prefer rm -i or -WhatIf (see course 7.11).
PatternMatchesExample files
*.txtany name ending in .txta1.txt, notes.txt
a?.txta, one character, .txta1.txt, a2.txt (not ab1.txt)
[ab]1.txta1.txt or b1.txta1.txt, b1.txt
photo[0-9].jpgphoto plus one digitphoto1.jpg, photo2.jpg
Step by step
  1. Open your terminal and cd into your sandbox practice folder. Run pwd to be sure.
  2. Type ls *.txt and press Enter. Only the .txt files are listed.
  3. Type ls a?.txt. Only names with exactly one character between a and .txt appear.
  4. Type ls [ab]1.txt and then ls photo[0-9].jpg. Compare with the table above.
  5. If you have a file with a space in its name, type ls "my file.txt" and then try it without quotes to see the error.
  6. PowerShell: use Get-ChildItem .txt (or ls .txt), and Get-ChildItem a?.txt. In PowerShell [ab]1.txt also works as a set.
  7. Check: before using any wildcard with rm or Remove-Item, you ran the same pattern with ls or Get-ChildItem first and the list was exactly what you expected.
Watch on YouTube
Command Line Basics for Beginners - Full CoursefreeCodeCamp.org · YouTube · youtube.com

Videos by other creators on YouTube, for reference. They are not made by or affiliated with The Future Market.

LESSON 01Wildcards: pick many files at once
LESSON 01 / ANIMATED LESSON / AI VOICE00:00 / 01:00
Read the video script
[Host] "A wildcard is a stand-in character. One pattern can match many files."
[Text on screen: * ? [ab]] "Star means anything, question mark means exactly one character, brackets mean one from a set."
[Screen: ls *.txt listing three files] "ls star dot txt lists every file ending in dot txt."
[Text on screen: Quote names with spaces] "If a name has a space, put it in quotes."
[Host] "Always preview a wildcard with ls before you use it with a delete command."
Try it now

In your sandbox, create a1.txt, a2.txt, b1.txt, photo1.jpg and photo2.jpg. Write the pattern that matches (1) only the photos, (2) only a1 and b1, (3) only a1 and a2. Test each with ls and write down the output.

ClaudeStuck? Copy a ready-made prompt for Claude

Copy this, open Claude, paste it, and Claude will walk you through the lesson step by step.

For a grown-up: Claude is for adults (18+). Copy this, paste it into Claude, and use the answer to explain the lesson to your child.

I'm learning "Command Line 2: files, search, pipes and scripts" on The Future Market. Lesson 1: "Wildcards: pick many files at once".

What the lesson teaches:
- Before this course: Command Line Basics (course 7.11). There you typed one file name at a time. Wildcards let you match many names with one pattern.
- On Mac and Linux the common wildcards are  (any number of characters, including none), ? (exactly one character) and [ab] or [0-9] (one character from a set or range).
- On Mac and Linux it is the shell, not the program, that expands the pattern, per the Bash manual (it calls this filename or pathname expansion). So ls .txt becomes ls a1.txt a2.txt notes.txt before ls even runs.
- In PowerShell, wildcard matching is done by the cmdlet receiving the pattern, per Microsoft's wildcard help. Get-ChildItem .txt works the same way for you as a user.
- Quotes matter. A file name with a space, such as my file.txt, must be quoted: ls "my file.txt". Without quotes the shell sees two names.
- A wildcard cannot see inside files; it only matches names. Hidden files (names starting with a dot) are normally not matched by  in Bash and zsh.
- Safety: a wildcard multiplies a command. rm .txt deletes every match. Always run ls .txt first to see what the pattern matches, then change ls to the real command, and prefer rm -i or -WhatIf (see course 7.11).

The exercise I'm working on:
In your sandbox, create a1.txt, a2.txt, b1.txt, photo1.jpg and photo2.jpg. Write the pattern that matches (1) only the photos, (2) only a1 and b1, (3) only a1 and a2. Test each with ls and write down the output.

I'm stuck. Please:
1. Explain the main idea in plain, simple words with one everyday example.
2. Walk me through the exercise one small step at a time. Ask me what I've done so far before giving the next step.
3. Don't just give me the final answer. Help me do it myself, and check my work when I share it.
I'm a parent helping my child (about 8 years old) with a lesson called "Wildcards: pick many files at once" from the course "Command Line 2: files, search, pipes and scripts".

Here's what the lesson says:
Instead of naming every toy one by one, you can say "all the red ones". A wildcard is a special character that stands for "anything", so one short command can work on lots of files.

The activity:
In your sandbox, create a1.txt, a2.txt, b1.txt, photo1.jpg and photo2.jpg. Write the pattern that matches (1) only the photos, (2) only a1 and b1, (3) only a1 and a2. Test each with ls and write down the output.

Please explain this so an 8-year-old understands: short sentences, a fun everyday example, and no hard words.
Then give me 3 simple questions I can ask my child to check they understood, and a way to do the activity together, one tiny step at a time.
Open Claude
Sources
My notes
02

Finding files with find and Get-ChildItem

This lesson is part of full access: every course and every level for one payment.

03

Searching inside files with grep and Select-String

This lesson is part of full access: every course and every level for one payment.

04

Pipes: chaining small commands together

This lesson is part of full access: every course and every level for one payment.

05

Redirection: saving output and hiding noise

This lesson is part of full access: every course and every level for one payment.

06

Environment variables and PATH

This lesson is part of full access: every course and every level for one payment.

07

Your first shell script, safely

This lesson is part of full access: every course and every level for one payment.

++

Final project

This lesson is part of full access: every course and every level for one payment.

??

Quiz

  1. What does *.txt match?

  2. Who expands a wildcard like *.txt on Mac and Linux?

  3. What is the difference between find and grep?

  4. Why quote ".txt" in find . -name ".txt"?

  5. What does grep -v ERROR app.log show?

  6. What is the PowerShell tool that works like grep?

  7. What does a pipe | do?

  8. What is the difference between > and >>?

  9. What does 2> /dev/null do?

  10. What is PATH?

  11. What does chmod +x script.sh do?

  12. Why should a script that changes files have a preview mode?

EX

Final exam

This lesson is part of full access: every course and every level for one payment.

CE

Certificate

This lesson is part of full access: every course and every level for one payment.