Way to append command line history to text file?

Discussion in 'General Linux' started by red, Nov 23, 2011.

  1. red

    red New Member

    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    I use command line a lot (as I'm sure most of you do too). I was just wondering if there was a way I could take, for example, the last 100 commands (like you do with the UP arrow) I did and place them into a text file for later reference.

    The reason I would like to do this is since I'm new to Linux, I'll be testing something on a VM and I would like to print out this file and make notes of where a certain string of commands did something I liked, or didn't like.

  2. grim76

    grim76 Active Member Staff Writer

    Messages:
    177
    Likes Received:
    48
    Trophy Points:
    28
    In your /home/<username> look for a file .bash_history (Provided that is the shell you are using) that should contain the list of commands that have been issued. There is also the command history that will spit out the entire list.
  3. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    198
    Trophy Points:
    43
    Sure..

    [xcode=bash]
    history > mycommands.txt
    [/xcode]

    Or.. last 100:
    [xcode=bash]
    history|tail -n 100 > mylast100commands.txt
    [/xcode]
  4. hackinjack

    hackinjack New Member

    Messages:
    22
    Likes Received:
    2
    Trophy Points:
    0
    Further to other answers, if you also want to know what time the commands were entered at, you can use:


    Code:
    HISTTIMEFORMAT="%d.%m.%y %T " history | tail  -100

Share This Page