Where is the log of used commands in Linux?
Solution 1
The file ~/.bash_history
saves the list of executed commands. At least in CentOS this file exists, I don't know if it exists in other distros.
Solution 2
A simple solution is to increase the number of commands saved and returned by history
. If you use bash, add this line to your ~/.profile
:
export HISTSIZE=100000
export HISTFILESIZE=999999
From man bash
:
HISTFILESIZE
The maximum number of lines contained in the history file. When
this variable is assigned a value, the history file is trun‐
cated, if necessary, to contain no more than that number of
lines by removing the oldest entries. The history file is also
truncated to this size after writing it when a shell exits. If
the value is 0, the history file is truncated to zero size.
Non-numeric values and numeric values less than zero inhibit
truncation. The shell sets the default value to the value of
HISTSIZE after reading any startup files.
HISTSIZE
The number of commands to remember in the command history (see
HISTORY below). If the value is 0, commands are not saved in
the history list. Numeric values less than zero result in every
command being saved on the history list (there is no limit).
The shell sets the default value to 500 after reading any
startup files.
Solution 3
There is no such log, at least not by default.
There are tools you can install, like acct
("GNU Accounting utilities for process and login accounting") which can keep track of all programs executed on the system.
acct
is packaged for most (probably all except tiny-distros) linux distros. The home page is at http://www.gnu.org/software/acct/
acct
provides the following commands, lastcomm
probably does what you're asking for:
ac prints statistics about users' connect time. ac can tell you how long a particular user or group of users were connected to your system, printing totals by day or for all of the entries in the wtmp file.
accton turns accounting on or off.
lastcomm lists the commands executed on the system, most recent first, showing the run state of each command. With last, you can search the acct file for a particular user, terminal, or command.
sa summarizes the information in the acct file into the savacct and usracct file. It also generates reports about commands, giving the number of invocations, cpu time used, average core usage, etc.
dump-acct dump-utmp display acct and utmp files in a human-readable format.
Related videos on Youtube
GShaik
Updated on September 18, 2022Comments
-
GShaik over 1 year
In Linux, generally we use a lot of commands and it is difficult to remember all of them.
history
command provides the list of commands we used previously but its limit is less. New commands are overwritten on old commands then old commands are missing. I think somewhere the log of the commands is stored in the system.
Is that log available to open and read? If possible can we change the maximum size of log that it can handle?
Is the output of
history
command depends upon the login-user? -
GShaik over 8 yearsIs there any log file that linux maintains for commands ?
-
terdon over 8 years@gafoor yes, the history file I mention in my answer. Nothing else by default. If you set the variables I shows, you will keep a list of thousands of commands.
-
GShaik over 8 yearsIn ubunutu file ~/.bash_history exists
-
terdon over 8 years@AbdulGafoor yes, but that's what you see when you run
history
. It will only have as many commands as those returned byhistory
. To keep more, you need to set the variables I show in my answer. -
ILikeTurtles over 8 yearsThis file also exists in Mac OSX. You can type vim ~/.bash_history to see the contents of the file under Mac.
-
0xSheepdog over 8 yearsUpvote over the other answers simply for precision of answering the query of OP. There is no such log by default. The OP is incorrect that there is some other, special log. The default log OP mentions is the right one, OP simply needs to modify settings to match requirements.
-
Admin over 8 yearsIt's the
HISTFILE
variable which sets the location history file, which by default (for bash) is ~/.bash_history -
terdon over 8 years@AbdulGafoor yes, each user has their own history file.
-
GShaik over 8 yearscan
root user
see all the user's history ? -
terdon over 8 years@AbdulGafoor yes, root can see everything that's not encrypted. Depending on your setup, other users can also see your history too. Basically, anyone who has read access to your
$HISTFILE
(~/.bash_history
, by default) can see your history.