Monday, October 14, 2013

Linux history command(change HISTSIZE variable)

History is a very handy command to see what was typed and executed in a shell for a period of time.
For example, you are troubleshooting Linux server and you want to see the last 20 commands executed.
$ history 20
Or you want to find all commands with sudo word in them.
$ history | grep sudo
You can combine with less, tail and so on, it all depends of your needs.
After search you’ve found a command with number 234 and you want to execute it again.
$ !234
For more details about history command -> man history.
So how this works, how long is history and how to change its size?
Shell command history is stored in a .bash_history file in your /home folder ( cat .bash_history to see all the entries there ).
Number of commands is defined by histsize variable.
Type
$ echo $HISTSIZE
or
$ env | grep HISTSIZE
to see the number of commands that can be stored in this file.
My default number on Oracle Linux is 1000.
But what if you want to store 3000 commands for example, how can you change this variable?
Well quite simply, just use gedit or vi editor.
Change .bash_profile, add HISTSIZE=3000, export this variable to override one in /etc/profile, save file and load the changes with
$ source .bash_profile
Your .bash_profile should look like this
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
………
HISTSIZE=3000
export PATH HISTSIZE
So now you can store up to 3000 command in your history.
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc

Related Posts:

  • File Permission trong Linux Một trong những thành phần chính của hệ điều hành Linux là hệ thống quyền hạn truy cập (permission) áp dụng cho mọi đối tượng (file, thư mục, link…). Hệ thống này đóng 1 vai trò quan trọng trong việc đem lại mức an ninh cao … Read More
  • Clear memory linuxLệnh dùng clear memory cho linux. sync; echo 3 > /proc/sys/vm/drop_caches free -m … Read More
  • Cấp quyền thực thi với sudoMột trong những câu hỏi thường gặp nhất của người mới sử dụng Ubuntu là về sudo. Cơ chế bảo mật này được kích hoạt mặc định trong Ubuntu và mang lại nhiều ưu điểm hơn cơ chế chuyển sang người dùng khác bằng su truyền thống… Read More
  • Các lệnh thông dụng xem thông tin phần cứng trên HĐH Linux Đầu tiên là lệnh xem RAM [root@localhost ~]#top Tasks: 508 total, 1 running, 507 sleeping, 0 stopped, 0 zombie Cpu(s): 4.7%us, 0.3%sy, 0.0%ni, 94.6%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 8289408k total, 3601696k used, 46877… Read More
  • Hiển thị tiến trình trong hệ thống Linux Một trong những công việc cần thiết khi quản trị hệ thống Linux đó là kiểm soát các tiến trình hiện đang chạy. Khi đã biết được những tiến trình nào đang chạy bạn có thể tắt những tiến trình gây giảm tốc độ của hệ thống. Ng… Read More