Viewing Command Operation Records
Command operation logs are recorded in the system history.
Displaying Historical Command Execution Records
When you install, upgrade, or uninstall Container Manager, or query the container restoration progress using Container Manager, the history command records are saved to the ~/.bash_history file. Therefore, you can directly view the .bash_history file to find the command records.
The history commands are cached in the memory and written to the ~/.bash_history file only when the terminal exits normally. Run the following command to write the history records in the memory to the .bash_history file:
history -a
Changing the Number of Historical Records
- Use an editor, such as the vim editor.
- Run the sed command. For example:
sed -i 's/^HISTSIZE=number/HISTSIZE=newNumber/' /etc/profile, where number indicates the number of commands before modification and newNumber indicates the number of commands after modification. For example, to change the number of saved commands from 1,000 to 200, run the following command:
1sed -i 's/^HISTSIZE=1000/HISTSIZE=200/' /etc/profile
After the modification, run the source /etc/profile command for the environment variables to take effect.
Changing the Timestamp of a Historical Command File
If you need to record the timestamp (with user and IP address information) in the historical command file, add the following configuration to the /etc/profile file:
export HISTTIMEFORMAT="%F %T $USER_IP:`whoami` "
After the modification, run the source /etc/profile command for the environment variables to take effect. After the timestamp is added, the history command output is as follows (the example IP address is 50.38.66.66 and the example user is root):
1 2 3 4 5 | 2025-12-02 20:44:34 50.38.66.66:root systemctl start container-manager.service 2025-12-02 20:44:34 50.38.66.66:root systemctl restart container-manager.timer 2025-12-02 20:44:34 50.38.66.66:root systemctl restart container-manager.service 2025-12-02 20:44:34 50.38.66.66:root systemctl status container-manager.service 2025-12-02 20:44:34 50.38.66.66:root systemctl status container-manager.service |
In addition, if you need to record historical commands in a user-defined file, set the HISTFILE environment variable in /etc/profile and run the source /etc/profile command for the environment variable to take effect. Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 | HISTDIR=~/log/container-manager # Configure the file for storing historical command records. HISTFILE="$HISTDIR/container-manager.log" mkdir -p $HISTDIR chmod 750 $HISTDIR touch $HISTFILE chmod 640 $HISTFILE USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` if [ -z $USER_IP ] then USER_IP=`hostname` fi export HISTTIMEFORMAT="%F %T $USER_IP:`whoami` " # history command output format: time, IP address, user name, and command execution PROMPT_COMMAND=' { date "+%Y-%m-%d %T - $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTFILE' # Write the history command to the configured file in real time. |
The log file path is ~/log/container-manager. Ensure that the drive space is sufficient and the permission on the log file is 640.