how can you use the HISTORY command in UNIX or is there an Alternative command to view your previous unix commands.

What information are you trying to get that you aren't getting from history? The history command lists all of the commands that have been executed by your user account. If you are looking for a particular command or commands, you can pipe history to grep to filter out what you are looking for.

For example, to see all commands containing the string 'mysql': history | grep mysql

The built-in help function offers a lot of information about how to use the history command too. Here is what I got when I ran the help command on history:

help history
history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps
 arg [arg...]
    Display or manipulate the history list.

    Display the history list with line numbers, prefixing each modified
    entry with a `*'.  An argument of N lists only the last N entries.

    Options:
      -c        clear the history list by deleting all of the entries
      -d offset delete the history entry at offset OFFSET.

      -a        append history lines from this session to the history file
      -n        read all history lines not already read from the history file
      -r        read the history file and append the contents to the history
        list
      -w        write the current history to the history file
        and append them to the history list

      -p        perform history expansion on each ARG and display the result
        without storing it in the history list
      -s        append the ARGs to the history list as a single entry

#
    if $HISTFILE has a value, that is used, else ~/.bash_history.

    If the $HISTTIMEFORMAT variable is set and not null, its value is used
    as a format string for strftime(3) to print the time stamp associated
    with each displayed history entry.  No time stamps are printed otherwise.

    Exit Status:
    Returns success unless an invalid option is given or an error occurs.

And an Internet search turns up several web pages with additional information, for example, the following:

Click Here

Hope this helps.

'history' is a bash function built into the shell. If your unix system has bash you should be able to simply run bash and then have access to it. Ksh also implements this.

There is an environment variable HISTSIZE that specifies the number of commands that history will save. I'm not sure what the default is, but I have mine set to 1000, so I have access to the last 1000 shell commands. You can also set the HISTCONTROL=ignoredups which will keep you from seeing duplicate commands in your history - a common occurance.

This works for the bash shell. Unix systems often use the Korn or C shells. They have different options to set these limits.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.