You are Here:
Download Linux Lite 5.4 RC1 today - See Release Announcements



Command shortcuts

Author (Read 4666 times)

0 Members and 1 Guest are viewing this topic.

Command shortcuts
« on: December 08, 2015, 07:19:08 PM »
 

Zead

  • Forum Regular
  • ***
  • 115
    Posts
  • Country: 00
  • Reputation: 20

  • Linux Lite: 2.6 64bit

  • MEMORY: 8Gb
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



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.



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. ;)
Last Edit: December 08, 2015, 07:22:34 PM by Zead
 


Re: Command shortcuts
« Reply #1 on: December 08, 2015, 07:56:31 PM »
 

gold_finger

  • Documentation Writer
  • Platinum Level Poster
  • *****
  • 1094
    Posts
  • Country: us
  • Reputation: 325
  • Linux Lite Member

  • Linux Lite: 3.2 64bit

  • CPU: Intel Core2 Duo E7500 3.0GHz

  • MEMORY: 4Gb

  • VIDEO CARD: Intel 4 Series Integrated Graphics
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
Try Linux Beginner Search Engine for answers to Linux questions.
 

Re: Command shortcuts
« Reply #2 on: December 08, 2015, 10:08:52 PM »
 

Zead

  • Forum Regular
  • ***
  • 115
    Posts
  • Country: 00
  • Reputation: 20

  • Linux Lite: 2.6 64bit

  • MEMORY: 8Gb
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
Last Edit: December 08, 2015, 10:16:54 PM by Zead
 

Re: Command shortcuts
« Reply #3 on: December 09, 2015, 09:57:43 AM »
 

avj

  • Gold Level Poster
  • *******
  • 530
    Posts
  • Country: us
  • Reputation: 110
  • Linux Lite Member

  • Linux Lite: 2.8 64bit

  • CPU: Dual core Intel Pentium D 2.80GHz

  • MEMORY: 2Gb

  • VIDEO CARD: AMD/ATI RC410 Radeon Xpress 200/1100
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.
I have not failed. Ive just found 10,000 ways that wont work. - Thomas Edison
 


Tags:
 


Download Linux Lite 5.4 RC1 today - See Release Announcements