Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

>_
Terminal & Command Line
0/10 completed
Beginner
What is the terminal?Navigating foldersWorking with files and foldersViewing files
Intermediate
Wildcards and finding filesPipes and redirectionText processing: grep, sort, cut and friends
Advanced
Environment variables and PATHPermissions and processes
Pro
Shell productivity: aliases, scripts and dotfiles
Tracks / Terminal & Command Line / Intermediate

Wildcards and finding files

Typing file names one by one doesn't scale. Wildcards (globs) let one pattern match many files, and find searches whole folder trees.

Wildcards (globbing)

Pattern Matches
* Any number of characters (including none)
? Exactly one character
[abc] One character from the set
[0-9] One digit
Linux terminal (simulator) · editable

The shell expands wildcards before running the command. ls *.jpg actually runs ls photo1.jpg photo2.jpg. You can see this with echo:

Linux terminal (simulator) · editable

When nothing matches, the pattern is left as-is (in bash).

Wildcards work with every command

Linux terminal (simulator) · editable

⚠️ Wildcards + rm = danger. rm * deletes everything in the folder, and rm * .txt (note the space!) deletes everything, then complains that .txt doesn't exist. Run ls with the same pattern first to preview what will be deleted.

Hidden files and wildcards

* doesn't match hidden files (names starting with .):

Linux terminal (simulator) · editable

find: search a folder tree

Wildcards only look in one folder. find searches recursively through every subfolder:

Linux terminal (simulator) · editable
Option Meaning
find PATH Where to start searching (. = here)
-name "pattern" Match the file name (quote the pattern!)
-iname "pattern" Match the name, ignoring case
-type f / -type d Only files / only directories
-size +10M Bigger than 10 MB (real machines)
-mtime -7 Modified in the last 7 days (real machines)
-exec cmd {} \; Run a command on each result (real machines)

Why quote the pattern? Without quotes, the shell would expand *.md in the current folder before find even sees it. Quoting passes the pattern to find so it can search every folder.

Real-world find recipes

bash
find . -name "*.log" -mtime +30 -delete       # delete logs older than 30 days
find . -name "node_modules" -type d -prune    # locate bulky node_modules folders
find . -type f -size +100M                     # find huge files eating your disk
find src -name "*.js" -exec wc -l {} +         # count lines in all JS files

locate and fd

  • locate filename searches a prebuilt index of your whole disk, so it's instant (run updatedb to refresh the index).
  • fd is a modern, faster, friendlier find (fd "\.md$"). It's worth installing.

Practice

  1. List all .txt files in Documents using a wildcard.
  2. Use find to locate every .sh file under your home folder.
  3. Find all directories inside projects.
  4. Copy every file in data whose name ends in .txt or .log into a new folder ~/backup, using wildcards.
Linux terminal (simulator) · editable
✎ Check your understanding

1.What does ls photo?.jpg match?

2.Why should you quote the pattern in find . -name "*.txt"?

← Viewing files