Ask Your Question

is there any way to find out what commands I have run so far on my terminal in the present installation of Fedora?

asked 2014-08-12 11:06:36 -0500

mohanprakash gravatar image

Is there any method to find out the history of commands run on terminal? I want to see all commands in my current installation of fedora.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2014-08-12 12:10:48 -0500

swilson gravatar image

The "history" command may be helpful or "~/bash_history" may provide what you need.

edit flag offensive delete link more

answered 2014-08-12 12:16:26 -0500

sideburns gravatar image

In general, you can look through your last 1000 commands by using the up and down arrows at the command prompt. (The size of your history list can be configured, but that's the default.) Once you have the command you're looking for, you can either execute it as is, or edit it and then execute. (This is very useful if you need to correct a typo in a long, involved command.) For more details on how you can use your bash history, try man history. The history command is one of the bash builtin commands, so you'll have to page down until you come to it in alphabetic order.

edit flag offensive delete link more

answered 2014-08-13 04:24:07 -0500

tonioc gravatar image

Another way - with advantage of giving the date and time of commands entered - is to use the bash DEBUG trap as a hook to log all commands entered from interactive shell to syslog or elsewhere. for example, create a file in /etc/profile.d/ , with:

function logcmd
  if  [ -n "$BASH_COMMAND" ] && [ -n "$PS1" ]; then
          logger -d -p local6.debug -t bash "${USER}[$$]: $BASH_COMMAND"

[ -n "$PS1" ] && trap logcmd DEBUG

The PS1 check prevents from logging commands from inside scripts that would flood the log. The unset PROMPT_COMMAND avoids useless output to syslog.

Note: to log commands from ssh sessions, you also need to add something in bashrc, for example:

if [ -n "$SSH_CLIENT" ] && [ -n "$BASH_EXECUTION_STRING" ]; then   
 logger -d -p local6.debug -t bash "${USER}[$$]: $BASH_EXECUTION_STRING"

See also and bash man page.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-08-12 11:06:36 -0500

Seen: 1,105 times

Last updated: Aug 13 '14