• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Friday, September 26, 2014

    How to prevent a command from getting stored in history in Linux

    Q: Is it possible to avoid commands getting stored in history in Linux?

    A: Yes, you can do so in bash shell using the below method

    In bash there is a variable HISTCONTROL which can be used to achieve our task. By default it contains a value of "ignoredups" as per which history command avoids keeping duplicate command records.

    Let us change it to something else
    # export HISTCONTROL=ignorespace
    Let us verify if the value is changed
    # echo $HISTCONTROL
    ignorespace


    Now as per this any command you run starting with a space will not be monitored or stored in history or and file defined under HISTFILE which by default is ~/.bash_history.

    Let us try to run some commands with a space

    Output of history before running command
    # history | tail -5
    412 echo $HISTCONTROL
    413 cd /etc/httpd/conf
    414 vi httpd.conf
    415 /etc/init.d/httpd status
    416 history | tail -5

    Run any command starting with an extra space
    #   date
    Verify your results
    # history | tail -5
    413 cd /etc/httpd/conf
    414 vi httpd.conf
    415 /etc/init.d/httpd status
    416 history | tail -5
    417 history | tail -5

    So as you see the date command executed is not stored.

    Making the changes permanent
    Now the variable change made is temporary and terminal based which means next time you login the HISTCONTROL variable will return to its default value.

    To make it permanent follow the below link
    How to set environment (PATH) variable permanently in Linux

    Related Articles
    View the history of commands along with time
    Long list the files on the basis of time


    Follow the below links for more tutorials

    What is the difference/comparison between Unix and Linux ?
    What are the maximum and minimum limits for RHEL 4 vs 5 vs 6 ?
    Step by Step Linux Boot Process Explained In Detail
    What is the difference between ext3 and ext4 filesystem in Linux ?
    How to configure Private Network in VMware Workstation
    10 examples to help you understand top command usage in Unix/Linux
    Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
    Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
    15 tips to enhance security of your Linux machine
    Why is Linux more secure than windows and any other OS
    Understanding Load Average in Linux and when to be worried about it?
    RAID levels 0, 1, 2, 3, 4, 5, 6, 0+1, 1+0 features explained in detail
    Understanding UMASK value in Linux
    How to keep a track of all the commands run by any user in Linux
    How do you check Linux machine is Physical or Virtual remotely?
    How to configure PXE boot server in Linux using Red Hat 6

    0 comments:

    Post a Comment