Unix Power ToolsUnix Power ToolsSearch this book

30.6. Using !$ for Safety with Wildcards

We all know about using ls before a wildcarded rm to make sure that we're only deleting what we want. But that doesn't really solve the problem: you can type ls a* and then mistakenly type rm s* with bad consequences -- it's just a minor slip of your finger. But what will always work is:

% ls a*
a1 a2 a3
% rm !$

(ls -d a* (Section 8.5) will make less output if any subdirectory names match the wildcard.)

Using the history mechanism to grab the previous command's arguments is a good way to prevent mistakes.

-- ML



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.