Linux Lite Forums

Software - Support => Tutorials => Topic started by: Zead on December 08, 2015, 07:19:08 PM

Title: Command shortcuts
Post by: Zead on December 08, 2015, 07:19:08 PM
I'm not sure if someone posted this already, but I've found this neat command line feature a while back.

Maybe you all already know about this, who knows.

Let's say you want to type in inside terminal: "sudo apt-get autoremove --purge", but instead, you can just type in "!1".

All you have to do is:

1) Open ".bash_history" located in /home/yourname/
2) Type in to the first line: sudo apt-get autoremove --purge

(http://i68.tinypic.com/2m5cl13.png)

3) Save, and you are done!
4) Now open your terminal, and for example type: !1 skype (And it will completely wipe out your skype including it's configuration files and all dependencies installed with it).

For example when I want to update my system, I just open my terminal and type in: !1, and then my password. Fast, easy.
Whatever you add to second line in ".bash_history" will be !2 and so on.

(http://i65.tinypic.com/20k6u1h.png)

Just please don't run the update command I have without knowing what you are doing. Linux Lite devs recommend not to run dist-upgrade.



I'm sure there are ways to bind the command lines to your keyboard macros, But I haven't found how to do that yet.

I hope this tutorial is helpful to someone. ;)
Title: Re: Command shortcuts
Post by: gold_finger on December 08, 2015, 07:56:31 PM
I'm guessing that the point of this is to set one or two commands that you use often as the first and second commands stored in bash history so they're easy to duplicate quickly -- correct?  Interesting idea.

Just keep in mind that bash history will overwrite those if the default limit of command history saved is reached.  (I think it's set to save up to 500 lines initially.)  So if you use the terminal a lot, check how many lines that history is up to every once in a while or you could be in for a surprise one day and execute commands that you didn't mean to.  Just open a terminal and enter history to see list of commands you've entered and how many lines have been saved so far.

NOTE:  for anyone who may not already know, you can re-run any command listed in history by preceding it's line number with a "!" and hitting enter.  Eg.  If you ran dpkg -l | grep 'flash' somewhere along the line to find out if you had flash installed and it showed up as line #235 in history, you'd just enter this in the terminal to re-run that command:
Code: [Select]
!235
Title: Re: Command shortcuts
Post by: Zead on December 08, 2015, 10:08:52 PM
I'm guessing that the point of this is to set one or two commands that you use often as the first and second commands stored in bash history so they're easy to duplicate quickly -- correct?  Interesting idea.

Just keep in mind that bash history will overwrite those if the default limit of command history saved is reached.  (I think it's set to save up to 500 lines initially.)  So if you use the terminal a lot, check how many lines that history is up to every once in a while or you could be in for a surprise one day and execute commands that you didn't mean to.  Just open a terminal and enter history to see list of commands you've entered and how many lines have been saved so far.

NOTE:  for anyone who may not already know, you can re-run any command listed in history by preceding it's line number with a "!" and hitting enter.  Eg.  If you ran dpkg -l | grep 'flash' somewhere along the line to find out if you had flash installed and it showed up as line #235 in history, you'd just enter this in the terminal to re-run that command:
Code: [Select]
!235
Yeah, my bash_history got messed up once because of this limit. I was thinking if there's solution to this from happening instead of deleting the history? Something other than increasing the limit
Title: Re: Command shortcuts
Post by: avj on December 09, 2015, 09:57:43 AM
This doesn't look like something that should be tried by people who are not used to using the command line.  It looks like it could cause a lot of trouble if you forget you used another command and then ran it.  Something like forgetting you deleted something using the rm command.