Wildcards and Shell Expansion Print

  • 0

What the shell does before running a command.

WHAT EXPANSION MEANS

The shell rewrites your command before the program ever sees it.

WHY THAT MATTERS

The program receives a list of filenames, not the pattern you typed.

WHAT AN ASTERISK MATCHES

Any sequence of characters, including none.

WHAT A QUESTION MARK MATCHES

Exactly one character.

WHAT SQUARE BRACKETS MATCH

Any one character from a set or range.

WHAT BRACE EXPANSION DOES

Generates a list from a pattern.

WHERE THAT HELPS

Creating several directories at once, or copying a file to a backup name in one step.

WHAT A DOT-PREFIXED FILE IS NOT MATCHED BY

A plain asterisk.

WHY THAT SURPRISES PEOPLE

Copying everything with an asterisk silently omits hidden files, which is most configuration.

WHAT HAPPENS WHEN NOTHING MATCHES

The pattern is passed through literally, in most shells.

WHY THAT CAUSES CONFUSION

A command receives a literal asterisk and reports a file not found with that name.

WHAT TO DO BEFORE ANY DESTRUCTIVE COMMAND WITH A WILDCARD

Run ls with the same pattern and read the output.

WHY

It shows exactly what the command will act on.

WHAT TO NEVER DO

Put a space between a path and an asterisk unintentionally.

WHY

Deleting a directory and everything in the current one are one keystroke apart.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot