0

Os : debian8. There are two users :normal and root.

touch /var/log/all.log
chmod  777  /var/log/all.log

For normal.

vim  /home/normal/.bashrc
export HISTTIMEFORMAT="%Y-%m-%d:%H-%M-%S:  `whoami` : "    
export PROMPT_COMMAND='history  > /var/log/all.log'

source /home/normal/.bashrc

All the history command for normal(the user) will write into /var/log/all.log.

For root the same way.

vim  /root/.bashrc
export HISTTIMEFORMAT="%Y-%m-%d:%H-%M-%S:  `whoami` : "    
export PROMPT_COMMAND='history  > /var/log/all.log'

source /root/.bashrc

All the history command for root(the user) will write into /var/log/all.log.

Now i want to combine the two configuration file into one file.
Delete the two lines in both /home/normal/.bashrc and /root/.bashrc .
1. Combine them into /etc/profile.

vim  /etc/profile    
export HISTTIMEFORMAT="%Y-%m-%d:%H-%M-%S:  `whoami` : "    
export PROMPT_COMMAND='history  > /var/log/all.log'    

source /etc/profile

All the history info for normal can't be written into /var/log/all.log.
All the history info for root can be written into /var/log/all.log.
2. Combine them into /etc/bash.bashrc .

vim  /etc/bash.bashrc     
export HISTTIMEFORMAT="%Y-%m-%d:%H-%M-%S:  `whoami` : "    
export PROMPT_COMMAND='history  > /var/log/all.log'

source /etc/bash.bashrc

All the history info for normal can't be written into /var/log/all.log.
All the history info for root can be written into /var/log/all.log.

Why can't combine the two configuration file --/home/normal/.bashrc and /root/.bashrc-- into just one file?

1

What you're looking for is $HISTFILE, and you get that information from man bash:

HISTFILE ---- The name of the file in which command history is saved (see HISTORY below). The default value is ~/.bash_history. If unset, the command history is not saved when a shell exits.

So, set $HISTFILE to /var/log/all.log in your profile and that should do it.

export HISTFILE=/var/log/all.log

1
  • Did this answer work for you? If so, please mark it as the correct answer. – iangolden Nov 10 '17 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.