Find the answer to your Linux question:
Results 1 to 4 of 4
so, I'm solid on linux basics, and have never written a shell script. But there is something I would like to get, or do. Would it be possible to have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2003
    Posts
    57

    log every linux command line for all users persistently?


    so, I'm solid on linux basics, and have never written a shell script. But there is something I would like to get, or do.

    Would it be possible to have linux log ALL COMMANDS I EVER TYPE in a single file? I.e., every ls -l and cd /this/folder etc., but also the install records I have done and more.

    If this file exists great. If there is a persistent file created for EACH session and user, then maybe I can write a script to conjoin the lines. Or, what other options are available?

    I'd like the file to have 3 columns - user executing, datetime executed, and copy of the command string. Some kind of results or error if returned would be great. MANY THANKS from a guy who is amazed what Linux is capable of doing!

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,410
    Many shells have a history file.
    Try calling this and see if it suits you
    Code:
    history
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Apr 2003
    Posts
    57
    looked at .bash_history and surpised it didn't log the time stamp as well as the command. No, I'm looking for something that would log 3 columns:

    1. username
    2. linux timestamp . microtime
    3. command
    (4). optional, any error returned if it produced an error

    .. and stored it in one file optionally.

    surprises me if linux doesn't have this - mysql and apache both have very nice logging options, and bash commands aren't entered nearly as much as web pages and db queries...

  4. $spacer_open
    $spacer_close
  5. #4
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,631
    The user isn't needed as each user has their own history file. You can add a timestamp but it will be in rows rather than columns.

    Edit /home/<user_name>/.bashrc or /etc/bash.bashrc if you want this to be global and add the following to the end of it
    Code:
    export HISTTIMEFORMAT="%F %T "
    The format string is the same as used in the strftime function. You can get the full details of this function by running
    Code:
    man 3 strftime
    Once this is done you can open a new shell and start running your commands. Run the history command to see the effect.
    "I used to be with it, then they changed what it was.
    Now what was it isn't it, and what is it is weird and scary to me.
    It'll happen to you too."

    Grandpa Simpson



    The Fifth Continent

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •