Ask Your Question
1

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 -0600

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
2

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

swilson gravatar image

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

edit flag offensive delete link more
2

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

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
0

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

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/logcmd.sh , with:

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

[ -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"
fi

See also http://superuser.com/questions/666021/bash-preexecute 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

Stats

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

Seen: 1,087 times

Last updated: Aug 13 '14