Wildcards and Tab Completion

What this is. A wildcard lets one word stand for many filenames. The shell expands it before the command runs, so the command never sees the star at all.

* matches any run of characters, including none.

? matches exactly one character.

So ls *.js lists every file ending in .js, and ls app.?s matches app.js and app.ts but not app.jsx.

✦ The shell expands, not the command

This is the detail that explains a whole class of confusion. When you type ls *.js, the shell replaces *.js with the matching filenames and then runs ls with those as arguments. The command has no idea a wildcard was involved. It is also why an unquoted wildcard passed to find gets expanded too early, which you will meet in a moment.

SANKOFA SANDBOX
learner:~$

The archive project has html, js, css and md files in it.

Try it → Run `cd projects/archive` then `ls *.js`, then `ls *.?ss`, then `ls *`. Then try `echo *.js` and notice the shell hands the same expanded list to a completely different command.

Tab completion is not a shortcut, it is a correctness tool. Type the first few characters of a path and press Tab, and the shell finishes it. If several things match, pressing Tab twice lists them.

The real value is that a completed path is a path that exists. Most no such file errors are typing errors, and Tab eliminates them. Experienced users type remarkably few full filenames.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: find, and Names With Spaces →
← Back