On Fri 24 Jun 2022 at 08:48:05 (-0400), rhkra...@gmail.com wrote:
> On Friday, June 24, 2022 03:02:35 AM Andrew M.A. Cater wrote:
> > The last suggestion, and it's the simplest:
> > 
> >  rm [filename] -rf
> > 
> > Train your brain and your fingers to move the rf to the end of the command
> > so that you _have_ to check what filename you are typing as you type it.
> > 
> > If you need to be doubly sure rm [filename] -irf will put in the
> > interactive prompt again.
> 
> I like all these suggestions, as well as Thomas' addition (although I'm not 
> sure I'm ambitious enough to go back and edit the comand buffer).

Ambitious? Line editing and command history are two of the most useful
things about working at the command line.

And I recommend that you train your fingers to type rm -i (similarly
for cp and mv) rather than relying on the system to add -i for you.
You can thereby avoid a lot of harm -i to your system (oops).

For mass deletions, I would:

Use rm -i … and check that the filenames being reflected are from the
tree you expected.

Recall the command, then first add a space at the start of the line,
and next, remove the -i. The space prevents the potent version of the
command (without the -i) being added to your history when you press
Return.¹

> I do something slightly different than what Andrew suggests, I put the 
> filespec 
> on the blank command line, and then go back and insert the rm -rf before the 
> filespec.

Slightly different, but I use this with other potent commands, like dd:

Start the command line with # space, followed by the command and its
arguments. Study what you have written, then delete the # (but leave
the space: you don't want such potent commands left in your history).

¹ You don't want to be able to later recall this command accidentally,
  in a different context. So put   export HISTCONTROL=ignoreboth
  into your .bashrc file, preventing lines starting with a space from
  being added to your command history.

Cheers,
David.

Reply via email to