Globbing is a powerful tool for file management, but like its cousin
the chainsaw, it is a dangerous tool that demands respect and caution in
its use. Remember that mv
, rm
, and
cp
can clobber files! Let’s take globbing for a spin
in this hazardous arena.
Let us begin by makinig some files and directories with these commands.
unix> mkdir jail unix> cd jail unix> touch rocky flattop joker penguin riddler unix> cd .. unix> ls -F alan betty chuck david emily faith jail/
How do we get the prisoners out? Watch this trick.
MAC:Tue Jan 04:13:22:tossme> ls alan chuck emily flattop joker riddler betty david faith jail penguin rocky
Notice the use of the . (dot). So all files are moved out of jail
into our cwd
. Let’s jail everyone whose name contains a
t
.
MAC:Tue Jan 04:13:22:tossme> mv *t* jail MAC:Tue Jan 04:13:24:tossme> ls jail betty faith flattop
Now watch this.
MAC:Tue Jan 04:13:24:tossme> ls jail/f* jail/faith jail/flattop
Here are all prisoners whose name begins with the letter
f
. So, globbing can be used to create sets of arguments for
UNIX commands.