Something to try

K

Kovax

Guest
If you are a fan of the history command you should give this a try.
If you are looking for a command that you have run in the past and type the command "history" (no quotes) it gives you a list of the last commands that were run on the system. Along with the commands it gives you a number next to each command.
Give this a try:
After you find the command that you would like to run again... instead of the familiar copy and paste it to run it.... try to run !number ex. !255 and enter ...poof the command will run.

Kovax
 


D

DevynCJohnson

Guest
Thanks for the tip! Here is a full example for everyone to see.

Code:
[email protected]:~$ history
  1  ls
  2  ll
  3  date
  4  history
[email protected]:~$ !3
date
Wed Jan 15 14:51:39 EST 2014
I never use this command. I prefer to press the up-key until I see the command I want. However, not all terminals offer this feature, so many people can benefit from "history".

By the way, to erase the history, use this command "history -c".
 
V

Virneto

Guest
@Kovax,

NiceOne!!
;)

Here's another one:
to re run last inserted command just type >_
!!

And when you get the "need to be root" message, just type >_
sudo !!
 
Last edited:
D

DevynCJohnson

Guest
@Kovax,

NiceOne!!
;)

Here's another one:
to re run last inserted command just type >_
!!

And when you get the "need to be root" message, just type >_
sudo !!
The last command I found to be VERY helpful. I never thought of that. Thanks! :D
 
K

KenJackson

Guest
I don't like those "!" commands because you can't see what's going to execute until it executes. I prefer to up-arrow and edit.

I also search the history for a command which I know I've executed recently like this (you may need to veryify "emacs" is in your SHELLOPTS variable):

Press CTRL-R and start typing a portion of the command. The most recent match will appear and update as you type. When you see the one you want, press:
  • ENTER to execute, or
  • An arrow key or emacs motion key (CTRL-E, CTRL-A, CTRL-B or CTRL-F) to edit, or
  • CTRL-R to pick the previous match
 
D

DevynCJohnson

Guest
@KenJackson I never knew about "CTRL-R". Thanks!

Does anyone else have a better alternative? This thread is getting more interesting.
 
Y

Yesyesloud

Guest
Quite handy. My !255: "bluez-test-adapter discoverable on". And a silly forum game comes out of !255... Although !1, !2 or !3 seem more mysterious :p
 
N

nazukia

Guest
The CTRL-R is the one that I use the most often

I don't like those "!" commands because you can't see what's going to execute until it executes. I prefer to up-arrow and edit.
Obviously dont call "!#" without check "history before"

The thing is that up and down is different than history, up and down in tie to your current shell session, meaning that if you have 2 different terminal, they dont have the same value for up and down

History is tie to the user commands history.

tips
1)history command read from ~/.bash_history

2) so tail -n20 ~/.bash_history, show the last 20 command you typed in any terminal

3) The default limit line of this file can be found like this:
echo $HISTSIZE

4) you can edit your ~/.bashrc file to change the value of this file


:)
 
P

pane-free

Guest
I like #13 best of all. Thanks Kovax for the thread and nazukia for the post!
 
Y

Yesyesloud

Guest
After this thread, I became used to typing "history | grep (...)" to find rather old input. Ctrl+R comes even more handy, thanks.

I've just managed to nano my way into expanding HISTSIZE to a number I guess I'll never reach... 500 is not enough for cli maniacs :p
 
M

MikeyD

Guest
There are a bunch of good CTRL commands in most terminals, many I wasn't aware of until recently:

Code:
Ctrl + A    Go to the beginning of the line you are currently typing on
Ctrl + E    Go to the end of the line you are currently typing on
Ctrl + L                  Clears the Screen, similar to the clear command
Ctrl + U    Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H    Same as backspace
Ctrl + R    Let’s you search through previously used commands
Ctrl + C    Kill whatever you are running
Ctrl + D    Exit the current shell
Ctrl + Z    Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W    Delete the word before the cursor
Ctrl + K    Clear the line after the cursor
Ctrl + T    Swap the last two characters before the cursor
Esc + T    Swap the last two words before the cursor
Alt + F    Move cursor forward one word on the current line
Alt + B    Move cursor backward one word on the current line
Tab        Auto-complete files and folder names
 
K

KenJackson

Guest
There are a bunch of good CTRL commands in most terminals, ...
Also, ALT-D deletes the word after the cursor. I use that one.

That's kind of the complement of CTRL-W. It's a shame they don't look like complements.
 


Staff online

Members online


Latest posts

Top