Repeat previous unix command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Repeat previous unix command

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-07-2008
syang68 syang68 is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 30 July 2008, 11:32 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Repeat previous unix command

Hi all,

Is there a way to bring back the previous unix command without retyping?

I tried the "arror up" key, and it seems not working (sun solaris). What is the correct way?

Thanks!
Sponsored Links
    #2  
Old 07-07-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 31 October 2014, 5:04 PM EDT
Location: Switzerland - GE
Posts: 5,840
Thanks: 162
Thanked 417 Times in 392 Posts
Depends what shell you are using...
e.g. for Solaris
if you use /usr/bin/ksh:

# set -o vi (if not done yet as EDITOR=... in .profile...)
then its Esc+ k (backward...) j (Forward)
This works because you have a history file set...
Sponsored Links
    #3  
Old 07-07-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 31 October 2014, 5:04 PM EDT
Location: Switzerland - GE
Posts: 5,840
Thanks: 162
Thanked 417 Times in 392 Posts
If its executing the last command XXX again,
Then just type:
r XXX (with ksh...)
The Following User Says Thank You to vbe For This Useful Post:
yatin (06-16-2012)
    #4  
Old 07-07-2008
spirtle spirtle is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 23 March 2010, 12:11 PM EDT
Location: Scotland
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
In tcsh (and bash?) you can use

!! to execute the previous command again,
!-n to execute again the nth to last command
!foo to execute again the last command beginning with the string foo
!?foo to execute again the last command containing the string foo

Append
Code:
:p

to display rather than execute the command.
Sponsored Links
    #5  
Old 07-07-2008
syang68 syang68 is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 30 July 2008, 11:32 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Repeat previous unix command

Thanks for your reply. I am using ksh.

In linux, if my last command is for example "ls -ltr |tail", I just hit the "arrow up " key to bring it (ls -ltr |tail) back on the command line and then verify it. This gives me the opportunity to display the command before executing it.

The command 'r' that vbe suggests is good, but it is executed before I even have the opportunity to dsplay it.

I need a command (or key stroke) in order to display and then repeat the execution without retyping the command. Any idea?

Thanks!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Repeat output of last command w/o repeating last command glev2005 UNIX for Advanced & Expert Users 5 01-21-2010 09:51 AM
Editing a previous command in unix newguineapig79 UNIX for Dummies Questions & Answers 3 06-11-2009 09:37 AM
Repeat last entered command ? vilius Shell Programming and Scripting 5 09-25-2007 06:15 AM
previous,next command in unix arulkumar UNIX for Dummies Questions & Answers 4 09-11-2007 07:34 AM
Repeat a command in a shell scotty UNIX for Dummies Questions & Answers 2 10-30-2002 01:42 AM



All times are GMT -4. The time now is 02:46 AM.