Results 1 to 4 of 4

Thread: Remove history in bash for root, how?

  1. #1
    Join Date
    Jun 2012
    Location
    Sweden
    Beans
    324
    Distro
    Ubuntu 12.04 Precise Pangolin

    Remove history in bash for root, how?

    I wanted to delete my command history in bash, so I ran history -c. Everything was fine. But when I did that as root, the history "disappeared temporary". When logging out from root and logging in again, the history was still left. How can I delete the commands I've written when I have been using sudo?

  2. #2
    Join Date
    Jul 2005
    Location
    I think I'm here! Maybe?
    Beans
    Hidden!
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: Remove history in bash for root, how?

    Using a sudo command from your own user login will not be in the root system files but still in your own hidden user's .bash_history file. As there is no enabled root user account in ubuntu, there will be no root version of bash history, as far as I'm aware.

    Use gedit to open that hidden file which is in your own home folder, and if you want to you can delete the lines which were sudo commands, and then save the file. I'm sure it will be possible to use grep and pipe to sed or awk to delete those lines with a single command, but I am not a bash guru so I'm afraid I can not tell you how to do that.

    EDIT:
    For my own edification I have just found out how. This command will delete all lines starting with sudo in your user bash history file when run from your user terminal; no need for grep.
    Code:
    sed -i '/sudo/d' .bash_history
    Last edited by ajgreeny; July 26th, 2012 at 12:36 PM.

  3. #3
    Join Date
    Jun 2012
    Location
    Sweden
    Beans
    324
    Distro
    Ubuntu 12.04 Precise Pangolin

    Talking Re: Remove history in bash for root, how?

    Many thanks! I love the community here!

  4. #4
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Remove history in bash for root, how?

    just an fyi recent sudo commands will also be visible in /var/log/auth.log

Bookmarks

Posting Permissions

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