Chapter 9. File-Naming Shortcuts

In This chapter:

  • Using Filename Patterns

  • Using {} To Generate Arguments

  • Directory Naming Shorthand

Many commands accept multiple filenames on the command line, but typing ten or 20 names—even one or two, if they're long—can quickly become tedious. This chapter discusses several shortcuts that the shell provides for specifying filenames, so you can enter commands with less typing:

  • Pattern operators, for matching filenames

  • {}, for generating arguments using specific strings

  • ˜name and =n, for referring to home directories and directory stack entries

Using Filename Patterns

The shell lets you specify filenames using a pattern, which is a notation that matches a group of filenames. Patterns are convenient because you can use them as a form of typing shorthand, and let the shell do the work of figuring out which filenames apply. You don't have to type them yourself. The pattern-matching characters are shown in Table 9-1.

Table 9-1. Filename-Matching Pattern Operators

Operator

Description

*

Match an arbitrary length sequence of characters

?

Match a single character

[…]

Match any character named between brackets

[^…]

Match any character not named between brackets (tcsh only)

^pattern

Match filenames not matching pattern (tcsh only)

In order to see how various patterns work, it's helpful to have some sample filenames to work with. Assume you're in a directory containing the following files:

% ls Imakefile makefile part3 part8 xprog.h Makefile oot-greet.tar part4 part9 ...

Get Using csh & tcsh now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.