ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÏÂhistoryÃüÁîÓ÷¨15Àý

·¢²¼Ê±¼ä:2009-10-28 14:00:39À´Ô´:ºìÁª×÷Õß:ÎÒ°®Ð¡Æó¶ì
½ñÌìÍøÉÏ¿´µ½Ò»ÆªºÃÎÄÕ£¬Ìù³öÀ´´ó¼Ò·ÖÏíһϠ(q):s
Èç¹ûÄã¾­³£Ê¹Óà ÐУ¬ÄÇôʹÓã¨ÀúÊ·£©ÃüÁî¿ÉÒÔÓÐЧµØÌáÉýÄãµÄЧÂÊ¡£±¾ÎĽ«Í¨¹ýʵÀýµÄ·½Ê½ÏòÄã½éÉÜ history ÃüÁîµÄ 15 ¸ö¡£
ʹÓà HISTTIMEFORMAT ÏÔʾʱ¼ä´Áµ±Äã´ÓÃüÁîÐÐÖ´ÐÐhistory ÃüÁîºó£¬Í¨³£Ö»»áÏÔʾÒÑÖ´ÐÐÃüÁîµÄÐòºÅºÍÃüÁî±¾Éí¡£Èç¹ûÄãÏëÒª²é¿´ÃüÁîÀúÊ·µÄʱ¼ä´Á£¬ÄÇô¿ÉÒÔÖ´ÐУº
# export HISTTIMEFORMAT='%F %T '
# history | more
1 2008-08-05 19:02:39 service network restart
2 2008-08-05 19:02:39 exit
3 2008-08-05 19:02:39 id
4 2008-08-05 19:02:39 cat /etc/redhat-release
×¢Ò⣺Õâ¸ö¹¦ÄÜÖ»ÄÜÓÃÔÚµ± HISTTIMEFORMAT Õâ¸ö»·¾³±äÁ¿±»ÉèÖÃÖ®ºó£¬Ö®ºóµÄÄÇЩÐÂÖ´ÐÐµÄ bash ÃüÁî²Å»á±»´òÉÏÕýÈ·µÄʱ¼ä´Á¡£ÔÚ´Ë֮ǰµÄËùÓÐÃüÁ¶¼½«»áÏÔʾ³ÉÉèÖà HISTTIMEFORMAT ±äÁ¿µÄʱ¼ä¡£[¸Ðл NightOwl ¶ÁÕß²¹³ä]
ʹÓà Ctrl+R ËÑË÷ÀúÊ·,Ctrl+R ÊÇÎÒ¾­³£Ê¹ÓõÄÒ»¸ö¿ì½Ý¼ü¡£´Ë¿ì½Ý¼üÈÃÄã¶ÔÃüÁîÀúÊ·½øÐÐËÑË÷£¬¶ÔÓÚÏëÒªÖظ´Ö´ÐÐij¸öÃüÁîµÄʱºò·Ç³£ÓÐÓᣵ±ÕÒµ½ÃüÁîºó£¬Í¨³£ÔÙ°´»Ø³µ¼ü¾Í¿ÉÒÔÖ´ÐиÃÃüÁî¡£Èç¹ûÏë¶ÔÕÒµ½µÄÃüÁî½øÐе÷ÕûºóÔÙÖ´ÐУ¬Ôò¿ÉÒÔ°´Ò»ÏÂ×ó»òÓÒ·½Ïò¼ü¡£
# [Press Ctrl+R from the command prompt, which will display the reverse-i-search prompt]
(reverse-i-search)`red¡®: cat /etc/redhat-release
[Note: Press enter when you see your command, which will execute the command from the history]
# cat /etc/redhat-release
Fedora release 9 (Sulphur)
¿ìËÙÖظ´Ö´ÐÐÉÏÒ»ÌõÃüÁîÓÐ 4 ÖÖ·½·¨¿ÉÒÔÖظ´Ö´ÐÐÉÏÒ»ÌõÃüÁʹÓÃÉÏ·½Ïò¼ü£¬²¢»Ø³µÖ´ÐС£
°´ !! ²¢»Ø³µÖ´ÐС£
ÊäÈë !-1 ²¢»Ø³µÖ´ÐС£
°´ Ctrl+P ²¢»Ø³µÖ´ÐС£
´ÓÃüÁîÀúÊ·ÖÐÖ´ÐÐÒ»¸öÖ¸¶¨µÄÃüÁî
ÔÚÏÂÃæµÄÀý×ÓÖУ¬Èç¹ûÄãÏëÖظ´Ö´ÐÐµÚ 4 ÌõÃüÁÄÇô¿ÉÒÔÖ´ÐÐ !4£º
# history | more
1 service network restart
2 exit
3 id
4 cat /etc/redhat-release
# !4
cat /etc/redhat-release
Fedora release 9 (Sulphur)
ͨ¹ýÖ¸¶¨¹Ø¼ü×ÖÀ´Ö´ÐÐÒÔÇ°µÄÃüÁî
ÔÚÏÂÃæµÄÀý×Ó£¬ÊäÈë !ps ²¢»Ø³µ£¬½«Ö´ÐÐÒÔ ps ´òÍ·µÄÃüÁ
# !ps
ps aux | grep yp
root 16947 0.0 0.1 36516 1264 ? Sl 13:10 0:00 ypbind
root 17503 0.0 0.0 4124 740 pts/0 S+ 19:19 0:00 grep yp
ʹÓà HISTSIZE ¿ØÖÆÀúÊ·ÃüÁî¼Ç¼µÄ×ÜÐÐÊý£¬½«ÏÂÃæÁ½ÐÐÄÚÈÝ×·¼Óµ½ .bash_profile Îļþ²¢ÖØеǼ bash shell£¬ÃüÁîÀúÊ·µÄ¼Ç¼Êý½«±ä³É 450 Ìõ£º
# vi ~/.bash_profile
HISTSIZE=450
HISTFILESIZE=450
ʹÓà HISTFILE ¸ü¸ÄÀúÊ·ÎļþÃû³Æ
ĬÈÏÇé¿öÏ£¬ÃüÁîÀúÊ·´æ´¢ÔÚ ~/.bash_history ÎļþÖС£Ìí¼ÓÏÂÁÐÄÚÈݵ½ .bash_profile Îļþ²¢ÖØеǼ bash shell£¬½«Ê¹Óà .commandline_warrior À´´æ´¢ÃüÁîÀúÊ·£º
# vi ~/.bash_profile
HISTFILE=/root/.commandline_warrior
ʹÓà HISTCONTROL ´ÓÃüÁîÀúÊ·ÖÐÌÞ³ýÁ¬ÐøÖظ´µÄÌõÄ¿
ÔÚÏÂÃæµÄÀý×ÓÖУ¬pwd ÃüÁî±»Á¬ÐøÖ´ÐÐÁËÈý´Î¡£Ö´ÐÐ history ºóÄã»á¿´µ½ÈýÌõÖظ´µÄÌõÄ¿¡£ÒªÌÞ³ýÕâЩÖظ´µÄÌõÄ¿£¬Äã¿ÉÒÔ½«HISTCONTROL ÉèÖÃΪ ignoredups£º
# pwd
# pwd
# pwd
# history | tail -4
44 pwd
45 pwd
46 pwd [Note that there are three pwd commands in history, after executing pwd 3 times as shown above]
47 history | tail -4
# export HISTCONTROL=ignoredups
# pwd
# pwd
# pwd
# history | tail -3
56 export HISTCONTROL=ignoredups
57 pwd [Note that there is only one pwd command in the history, even after executing pwd 3 times as shown above]
58 history | tail -4
ʹÓà HISTCONTROL Çå³ýÕû¸öÃüÁîÀúÊ·ÖеÄÖظ´ÌõÄ¿
ÉÏÀýÖÐµÄ ignoredups Ö»ÄÜÌÞ³ýÁ¬ÐøµÄÖظ´ÌõÄ¿¡£ÒªÇå³ýÕû¸öÃüÁîÀúÊ·ÖеÄÖظ´ÌõÄ¿£¬¿ÉÒÔ½« HISTCONTROL ÉèÖÃ³É erasedups£º
# export HISTCONTROL=erasedups
# pwd
# service httpd stop
# history | tail -3
38 pwd
39 service httpd stop
40 history | tail -3
# ls -ltr
# service httpd stop
# history | tail -6
35 export HISTCONTROL=erasedups
36 pwd
37 history | tail -3
38 ls -ltr
39 service httpd stop
[Note that the previous service httpd stop after pwd got erased]
40 history | tail -6
ʹÓà HISTCONTROL Ç¿ÖÆ history ²»¼ÇסÌض¨µÄÃüÁî
½« HISTCONTROL ÉèÖÃΪ ignorespace£¬²¢ÔÚ²»Ïë±»¼ÇסµÄÃüÁîÇ°ÃæÊäÈëÒ»¸ö¿Õ¸ñ£º
# export HISTCONTROL=ignorespace# ls -ltr# pwd# service httpd stop [Note that there is a space at the beginning of service, to ignore this command from history]# history | tail -367 ls -ltr68 pwd69 history | tail -3ʹÓà -c Ñ¡ÏîÇå³ýËùÓеÄÃüÁîÀúÊ·
Èç¹ûÄãÏëÇå³ýËùÓеÄÃüÁîÀúÊ·£¬¿ÉÒÔÖ´ÐУº
# history -c
ÃüÁîÌæ»»
ÔÚÏÂÃæµÄÀý×ÓÀ!!:$ ½«Îªµ±Ç°µÄÃüÁî»ñµÃÉÏÒ»ÌõÃüÁîµÄ²ÎÊý£º
# ls anaconda-ks.cfg
anaconda-ks.cfg
# vi !!:$
vi anaconda-ks.cfg
²¹³ä£ºÊ¹Óà !$ ¿ÉÒԴﵽͬÑùµÄЧ¹û£¬¶øÇÒ¸ü¼òµ¥¡£[¸Ðл wanzigunzi ¶ÁÕß²¹³ä]ÏÂÀýÖУ¬!^ ´ÓÉÏÒ»ÌõÃüÁî»ñµÃµÚÒ»Ïî²ÎÊý£º
# cp anaconda-ks.cfg anaconda-ks.cfg.bak
anaconda-ks.cfg
# vi -5 !^
vi anaconda-ks.cfg
ΪÌض¨µÄÃüÁîÌæ»»Ö¸¶¨µÄ²ÎÊý
ÔÚÏÂÃæµÄÀý×Ó£¬!cp:2 ´ÓÃüÁîÀúÊ·ÖÐËÑË÷ÒÔ cp ¿ªÍ·µÄÃüÁ²¢»ñÈ¡ËüµÄµÚ¶þÏî²ÎÊý£º
# cp ~/longname.txt /really/a/very/long/path/long-filename.txt
# ls -l !cp:2
ls -l /really/a/very/long/path/long-filename.txt
ÏÂÀýÀ!cp:$ »ñÈ¡ cp ÃüÁîµÄ×îºóÒ»Ïî²ÎÊý£º
# ls -l !cp:$
ls -l /really/a/very/long/path/long-filename.txt
ʹÓà HISTSIZE ½ûÓà history
Èç¹ûÄãÏë½ûÓà history£¬¿ÉÒÔ½« HISTSIZE ÉèÖÃΪ 0£º
# export HISTSIZE=0
# history
# [Note that history did not display anything]
ʹÓà HISTIGNORE ºöÂÔÀúÊ·ÖеÄÌض¨ÃüÁî
ÏÂÃæµÄÀý×Ó£¬½«ºöÂÔ pwd¡¢ls¡¢ls -ltr µÈÃüÁ
# export HISTIGNORE=¡±pwd:ls:ls -ltr:¡±
# pwd
# ls
# ls -ltr
# service httpd stop
# history | tail -3
79 export HISTIGNORE=¡±pwd:ls:ls -ltr:¡±
80 service httpd stop
81 history
[Note that history did not record pwd, ls and ls -ltr]
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 5 ÌõÆÀÂÛ

  1. mengjie213 ÓÚ 2009-12-21 23:32:01·¢±í:

    ÊǸö²»´íµÄÌû×Ó¡£
    ¶¥£¡£¡£¡

  2. ÂúÁ³ºú×Ó ÓÚ 2009-11-02 13:52:25·¢±í:

    ÒýÓÃ:



    ÈÏÕæ¿´ÏÂÀ´£¬ÐèÒªÓÂÆøµÄ:0wpoi2
    ÎÒ°®Ð¡Æó¶ì ·¢±íÓÚ 2009-10-30 09:13


    ÎÒûÓÂÆø°¢£¬Åå·þÂ¥Ö÷µÄÓÂÆø°¢ (e:e2s

  3. ÎÒ°®Ð¡Æó¶ì ÓÚ 2009-10-30 09:13:40·¢±í:

    ÒýÓÃ:
    àÞàÞ£¬Ì«³¤ÁË
    wangyu ·¢±íÓÚ 2009-10-28 17:25



    ÈÏÕæ¿´ÏÂÀ´£¬ÐèÒªÓÂÆøµÄ:0wpoi2

  4. wangyu ÓÚ 2009-10-28 17:25:00·¢±í:

    àÞàÞ£¬Ì«³¤ÁË

  5. Dnirta ÓÚ 2009-10-28 15:09:58·¢±í:

    ˳·ѧϰ