Results 1 to 5 of 5

Thread: Modify a command from the bash shell history before using it again?

  1. #1
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Modify a command from the bash shell history before using it again?

    I suppose this is almost sort of a trivia question, but is there a way to pull up a previous command from the bash shell history and modify it before using it? Other than doing a copy and paste I mean. For instance, if I do:
    Code:
    history
    And I see that command number 423 is:
    Code:
    423  cat /boot/grub/menu.lst
    So if I want to re-execute that command I could simply do:
    Code:
    !423
    But what if I want to modify that command slightly before executing it? Is there an easy way of doing that? Just curious.

  2. #2
    Join Date
    Feb 2007
    Location
    The hills of appalachia
    Beans
    966

    Re: Modify a command from the bash shell history before using it again?

    May not be what you are looking for but I edit the history file in a word processor. Open nautilus and hit ctrl-H to show hidden files and look for .bash_history. Open it in gedit or whatever editor you like to use and edit. You will probably have to restart the terminal for the changes to take effect, tho i might be wrong.
    If you think you're free, there's no escape possible. Ram Dass

  3. #3
    Join Date
    Oct 2006
    Beans
    513

    Re: Modify a command from the bash shell history before using it again?

    Uh. press up (the arrow keys) of ctrl+p revious / ctrl+n ext if you use standard (emacs) bindings. or esc k/j if you use vi bindings

    EDIT: Ah, I think I missunderstood what you wanted
    EDIT2: If you use vi bindings you could do "esc 432k" maybe emacs have something similar
    Last edited by olejorgen; August 16th, 2008 at 04:35 PM.
    Donation links
    Free hardware
    Petition for free drivers
    If every forum member donated $1 to FSF, they would almost double their income

  4. #4
    Join Date
    Oct 2006
    Beans
    513

    Re: Modify a command from the bash shell history before using it again?

    Or you could use zsh and do !423<tab>
    Donation links
    Free hardware
    Petition for free drivers
    If every forum member donated $1 to FSF, they would almost double their income

  5. #5
    Join Date
    Feb 2007
    Location
    The hills of appalachia
    Beans
    966

    Re: Modify a command from the bash shell history before using it again?

    see also Bash History. The fc command mentioned there may help.
    If you think you're free, there's no escape possible. Ram Dass

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •