Live data from Hacker News

$!134 can be a nice bash foot shooter if you accidentally mistype the number

news.ycombinator.com

21–30 of 54 posts

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#21
post #18
post #2

Fortunately my memory was never good enough for me to use that facility. C-r is how I always lookup earlier commands.

Can you navigate C-r history, or are you forced to see only the last command?

I've noted once within my personal bash cheat sheet this:

Search the command history

* Search as you type: Ctrl + r and type the search term; Repeat Ctrl + r to loop through results.

* Search the last remembered search term: Ctrl + r twice.

* End the search at current history entry: Ctrl + j

* Cancel the search and restore original line: Ctrl + g

Try of course at your own risk. But works for me.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#24

I don't use the terminal often, but when I do, the feeling of sheer power and control over the system is palpable. I'm a fast and nervous typer, so I always try to slow down and notice all the ways I could lose data, and how easy it would be to make such mistakes (eg. how many mistyped letters away from wiping my database am I?). Over time, I got better at noticing danger areas. Whenever I use 'rm', I re-read the com…

Regarding `rm`, I usually have something like this setup in my bashrc/zshrc: rm () { mv "$@" ~/.trash } So any time I use rm, it actually just moves it to ~/.trash instead. Not fool-proof nor perfect, but have saved me at least once so found it to be good enough for now.

I'd be afraid of relying too much on this only to, at some point, be on a server or user that doesn't have this and accidentally deleting something too early.

Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#25

Earlier quoted context omitted.

Regarding `rm`, I usually have something like this setup in my bashrc/zshrc: rm () { mv "$@" ~/.trash } So any time I use rm, it actually just moves it to ~/.trash instead. Not fool-proof nor perfect, but have saved me at least once so found it to be good enough for now.

I'd be afraid of relying too much on this only to, at some point, be on a server or user that doesn't have this and accidentally deleting something too early. Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

> Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

But this would defeat the original purpose, i.e. the prevention of someone accidentally using rm.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#27

Earlier quoted context omitted.

I'd be afraid of relying too much on this only to, at some point, be on a server or user that doesn't have this and accidentally deleting something too early. Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

> Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe. But this would defeat the original purpose, i.e. the prevention of someone accidentally using rm.

If you get used to using a different command, you won't use `rm` accidentally

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#28

Earlier quoted context omitted.

I'd be afraid of relying too much on this only to, at some point, be on a server or user that doesn't have this and accidentally deleting something too early. Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe.

> Maybe it'd be best to just give this command a new name like `delete` or `trash` just to be safe. But this would defeat the original purpose, i.e. the prevention of someone accidentally using rm.

Not necessarily. If you get used to using `delete` all the time, that is most likely what you would use on the server too. Once you trip over it missing, you are reminded that you are in dangerous territory.

Re: $!134 can be a nice bash foot shooter if you accidentally mistype the number

#29

Not foolproof either, but export HISTIGNORE="* rm *" makes calls to rm not show up in the history, for better or worse.

I've added now both:

export HISTIGNORE="* rm *"

export HISTIGNORE="rm *"

I think it's even a bit better. Better preventing worst case if possible right from the start. And usually you don't need rm commands within your history. At least I don't.

Post reply on HN