How To Discover Which Files Your Command Will Affect

Using globs at the Linux command line is a powerful way of selecting multiple files, the most common globs being * which matches zero or more characters, ? which matches just one character, and [xyz] which will match x or y or z.

When constructing a complex glob, it's useful to be able to test just exactly what it will do.

The Bash shell can do this with two commands, CTRL-x g and CTRL-x *. Here’s an example of them in use. First, CTRL-x g:

# ls l* [user now types CTRL-x g]
libvirt-bin lm-sensors loadcpufreq lvm2
# ls l*

Here, the shell lists all the matching files and then redisplays the command line.

Now CTRL-x *:

# ls l* [user now types CTRL-x *]
# ls libvirt-bin lm-sensors loadcpufreq lvm2

In this case, the shell redisplays the command line and replaces the glob with a list of matching filenames.

Back to Linux Tips and Advice

© 2012 Tiger Computing Ltd, Wyastone Business Park, Wyastone Leys, Monmouth, NP25 3SR | Legal | Sitemap