Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I run the most recent command again from history in AIX Server? And how to edit the most recent command and run it again in AIX?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

what shell are you using?

if korn?

'r' will run the previous

bash?

ctrl-p or up-arrow or '!!'

to edit the command try using fc - it will used the $EDITOR env variable and open up the editor. For example if it's vi then it'll open vi with the command and when you save exit (ZZ or wq) it'll run it.

share|improve this answer
    
I'm using the Korn shell –  jrara Nov 27 '12 at 7:15
    
How to edit the last statement before running it? –  jrara Nov 27 '12 at 7:16
    
set -o vi for example will give you inline interaction with the command line using vi command mode. That said, ESC invokes the mode and you can use the standard hjkl movement keys as well as many of the other vi motion keys to move around and modify your command. –  mattcaffeine Nov 29 '12 at 4:40
add comment

With bash, you can try

!!

to replay the last command you used. Don't know if it works with Korn.

share|improve this answer
add comment

If you comfortable using vi, the best way is to set your shell editor to vi by running command:

set -o vi

then

esc-k will give you the last run command

subsequent presses on keys "j" and "k" (both lower case) will take you up and down in the command history.

if you want to edit a line, use keys "h" and "l" (lower case again) to move "left" and "right" respectively. Use "x" to delete character under cursor. Hit "i" to go into insert mode to add characters and words, hit esc again to go back to cursor moving mode. I know it sounds complex and archaic, but if you know vi, these actions come to you like a second nature (and in my opinion, every UNIX sysadmin should learn vi at least in a moderate level)

Having said all of this, you can use the command

set -o emacs

and recall the command history with cursor up/down keys and edit the line with cursor left/right keys. Use backspace and delete keys just like you use them in a DOS prompt. But this requires that you are using a good terminal emulator (PuTTY is fine by the way) and emacs application to be installed properly (most of the time it is fine as it comes with the OS)

I am not sure which one is better for you and which one is more applicable in your case.

Good luck

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.