Linux konsolu kullanırken konsol üzerinde çalıştırdığımız her komut bash history dosyasında yani varsayılan dosya ‘~ / .bash_history’ içerisinde tutulur. Komut geçmişini görmek için en basit kullanım:
1 |
# history |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
root@omeroner ~]$ history 4 ping google.com 5 echo $PS1 6 tail -f /var/log/messages 7 tail -f /var/log/messages 8 exit 9 clear 10 history 11 clear 12 history |
Bu çıktıya tarih zaman damgasını eklemek için daha önce paylaştığım history dosyasına tarih damgası ekleme yazısını inceleyebilirsiniz.
1 |
# export HISTTIMEFORMAT='%F %T ' |
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@omeroner~]$ export HISTTIMEFORMAT='%F %T ' 1 2013-06-09 10:40:12 cat /etc/issue 2 2013-06-09 10:40:12 clear 3 2013-06-09 10:40:12 find /etc -name *.conf 4 2013-06-09 10:40:12 clear 5 2013-06-09 10:40:12 history 9 2013-06-09 10:40:12 ping google.com 10 2013-06-09 10:40:12 echo $PS1 |
1 2 3 |
%F Equivalent to %Y - %m - %d %T Replaced by the time ( %H : %M : %S ) |
History dosyasında kayıt edilmesini istemediğimiz, filtrelemek istediğimiz komutları belirtebiliriz. Aşağıdaki komut ile ls -l,pwd ve date komutlarını ,history dosyasında göremeyeceğiz.
1 |
# export HISTIGNORE='ls -l:pwd:date:' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@omeroner~]$export HISTIGNORE='ls -l:pwd:date:' [root@omeroner~]$ls -l total 8 -rw-------. 1 root root 1297 Mar 7 2014 anaconda-ks.cfg -rw-r--r-- 1 root root 87 Jan 27 17:54 omer [root@omeroner~]$pwd /root [root@omeroner~]$pwd /root [root@omeroner~]$pwd /root [root@omeroner~]$date Thu May 14 15:40:02 EEST 2015 [root@omeroner~]$date Thu May 14 15:40:04 EEST 2015 [root@omeroner~]$history 5 964 24/03/15 14:11:54 ll 965 24/03/15 14:11:58 clear 966 14/05/15 15:39:42 history 967 14/05/15 15:39:52 export HISTIGNORE='ls -l:pwd:date:' 968 14/05/15 15:40:07 history 5 [root@omeroner~]$ |
Aşağıdaki komut ile kullanıcı tarafından üst üste yinelenen komutlar girilirse bunları görmezden gelicektir.Bir kullanıcı konsol üzerinden (bash) aynı komutu birden çok kez çalıştırsa bile yalnızca tek bir kayıt ve kayıt tarihi görünecektir.
1 |
[root@omeroner ~]$ export HISTCONTROL=ignoredups |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[root@omeroner ~]$export HISTCONTROL=ignoredups [root@omeroner ~]$pwd /root [root@omeroner ~]$pwd /root [root@omeroner ~]$pwd /root [root@omeroner ~]$pwd /root [root@omeroner ~]$date Thu May 14 15:49:05 EEST 2015 [root@omeroner ~]$date Thu May 14 15:49:06 EEST 2015 [root@omeroner ~]$ll total 8 -rw-------. 1 root root 1297 Mar 7 2014 anaconda-ks.cfg -rw-r--r-- 1 root root 87 Jan 27 17:54 omer [root@omeroner ~]$ll total 8 -rw-------. 1 root root 1297 Mar 7 2014 anaconda-ks.cfg -rw-r--r-- 1 root root 87 Jan 27 17:54 omer [root@omeroner ~]$history 9 970 14/05/15 15:47:08 history 10 971 14/05/15 15:47:36 export HISTCONTROL=ignoredups 972 14/05/15 15:47:38 pwd 973 14/05/15 15:47:43 history 10 974 14/05/15 15:48:46 export HISTCONTROL=ignoredups 975 14/05/15 15:49:00 pwd 976 14/05/15 15:49:05 date 977 14/05/15 15:49:11 ll 978 14/05/15 15:49:16 history 9 [root@omeroner ~]$ |
set edilen bu değişkenleri unset etmek için:
1 |
[root@omeroner ~]$ unset export HISTCONTROL |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
[root@omeroner ~]$unset export HISTCONTROL [root@omeroner ~]$ll total 8 -rw-------. 1 root root 1297 Mar 7 2014 anaconda-ks.cfg -rw-r--r-- 1 root root 87 Jan 27 17:54 omer [root@omeroner ~]$ll total 8 -rw-------. 1 root root 1297 Mar 7 2014 anaconda-ks.cfg -rw-r--r-- 1 root root 87 Jan 27 17:54 omer [root@omeroner ~]$ll total 8 -rw-------. 1 root root 1297 Mar 7 2014 anaconda-ks.cfg -rw-r--r-- 1 root root 87 Jan 27 17:54 omer [root@omeroner ~]$pwd /root [root@omeroner ~]$pwd /root [root@omeroner ~]$pwd /root [root@omeroner ~]$history 9 978 14/05/15 15:49:16 history 9 979 14/05/15 15:52:12 unset export HISTCONTROL 980 14/05/15 15:52:14 ll 981 14/05/15 15:52:15 ll 982 14/05/15 15:52:15 ll 983 14/05/15 15:52:19 pwd 984 14/05/15 15:52:20 pwd 985 14/05/15 15:52:22 pwd 986 14/05/15 15:52:25 history 9 [root@omeroner ~]$ |
Kalıcı export komutunu kaydetmek için .bash_profile dosyasına aşağıdaki gibi bir giriş yapın.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@omeroner ~]$ vim .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs export HISTCONTROL=ignoredups PATH=$PATH:$HOME/bin export PATH |
Konsol üzerinden çalıştırılan komutların geçmişini tutmak istenmeyebilir. Bunun için:
1 |
[root@omeroner ~]$ export HISTSIZE=0 |
yada
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@omeroner ~]$ vi .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin HISTSIZE=0 export PATH |
Komut geçmişini temizlemek için:
1 |
[root@omeroner ~]$ history -c |
Grep yardımıyla komut geçmişinde arama yapma:
1 2 3 4 5 6 |
[root@omeroner ~]$ history | grep pwd 113 2013-06-09 10:40:12 pwd 141 2013-06-09 10:40:12 pwd 198 2013-06-09 15:46:23 history | grep pwd 202 2013-06-09 15:47:39 history | grep pwd |
Ctrl+r komutu ile son çalıştırılan komutlar içerisinde arama yapılabilir:
1 |
(reverse-i-search)`source ': source .bash_profile |
daha sonrasında Enter ‘a basılarak komut çalıştırılabilir.
113 satır numarasında bulunan pwd komutunu tekrar çalıştırmak için:
1 |
[root@omeroner ~]#!113 |
Daha önce kullanılan komutu (netstat -np | grep 22) hatırlamak için “!” kullanabiliriz.
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@omeroner ~]$ !net netstat -np | grep 22 (No info could be read for "-p": geteuid()=501 but you should be root.) tcp 0 68 192.168.50.2:22 192.168.50.1:1857 ESTABLISHED - tcp 0 0 192.168.50.2:22 192.168.50.1:2516 ESTABLISHED - unix 2 [ ] DGRAM 12284 - @/org/freedesktop/hal/udev_event unix 3 [ ] STREAM CONNECTED 14522 - unix 2 [ ] DGRAM 13622 - unix 3 [ ] STREAM CONNECTED 12250 - @/var/run/hald/dbus-ujAjOMNa0g unix 3 [ ] STREAM CONNECTED 12249 - unix 3 [ ] STREAM CONNECTED 12228 - /var/run/dbus/system_bus_socket unix 3 [ ] STREAM CONNECTED 12227 - |
history kullanımıyla ilgili daha fazla bilgi için sayfasını ziyaret edebilirsiniz.
So, what do you think ?