We help IT Professionals succeed at work.

I want to record all the commands ran by any user(or root) in Linux

Last Modified: 2016-02-11
I need this mechanism via bash script or any RHEL Package.
Watch Question

Sean FitzpatrickSr Lab Systems Engineer

ex. given from FreeBSD
cat /usr/home/%username/.bash_history >> %username%history.log

You'll need to update the path for the user depending on what kernel version you are using.
Also you will need to run the cat as a root user or with sudo depending on kernel, so that you can read other user's bash_history files.
Easy way to figure out where the history files are located is my doing a 'locate history', if you don't have locate installed you can install mlocate, then run an updatedb; after you have done that, retry running the 'locate history' command.

Also: Is this something that you want to do once? or constantly update? If you want to constantly update the file, use the >> if you want to rewrite the file every time use > instead.
Most Valuable Expert 2015

Turn on auditing and require sudo (logging the commands) for all privileged commands even if you don't require knowing the root password.
Zephyr ICTCloud Architect

Like _jesper_ said, I think auditing is the way to go.


I found the solutions !


One more thing I want to send/save the files generated from script command to an oracle database. How i can achieve that ?


One more thing, how I can get rid of garbage created by the interactive commands like vi from script command.
Most Valuable Expert 2015

What do you mean by "garbage"?  Can you give an example?
Top Expert 2015

snoopy from epel does it. How you pump syslog to oracle is another question. Mostly syslog servers have semimaintained oracle modules that you need to fix before using.


Hi All,

@jesper - from garbage i mean ASCII code generated in the files while recording shell via script command.

@gheist - Thanks . snoopy is great tool, I will look on it and I want these logs piped to oracle.

I have a blog , do you think it can work what i need ?


Thanks All !
Top Expert 2015
This one is on us!
(Get your first solution completely free - no credit card required)


Thank you

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.