五、history命令 做用:查看和使用歷史命令(最多紀錄1000條) 保存位置:~/.bash_history 一、在啓動終端的時候,會自動從~/.bash_history中讀取歷史命令,加載到內存中 二、在終端中執行命令,命令的歷史記錄是保存在內存中 三、在關閉終端的時候,會將內存中的歷史命令自動保存到~/bash_history中 history的快捷操做 !num:執行歷史命令中編號爲num的歷史命令 !string:在歷史命令中找以指定字符串爲開頭的命令執行一次,從下向上進行查找 !!:執行的是上一個命令 !-num:執行歷史命令中倒數第num條命令 若是保留了歷史命令,******了咱們的系統,經過歷史命令,知道服務器進行了哪些操做。有些時候須要對歷史命令進行控制。 -c:清空歷史命令 (內存中的) 在啓動終端的時候,會從~/.bash_history讀取歷史命令 [root@localhost ~]# history -c [root@localhost ~]# [root@localhost ~]# history 1 history -a:手動將內存中的歷史命令保存到文件中 -r:從新從~/.bash_history中讀取歷史命令 -d: num:刪除指定編號的歷史命令(***別人系統的時候,抹掉本身的操做命令) 六、ls命令 做用:顯示當前或者指定目錄下的文件 選項 -a:顯示目錄下的所有文件(包括隱藏文件) -l:顯示文件和目錄的詳細屬性 -d:顯示目錄自身(若是不使用-d則是顯示目錄中的文件) -h:結合-l使用,以易讀的方式顯示目錄的大小,(只顯示 文件的大小,不顯示目錄的大小) -t: 按照文件的修改時間排序,將最後修改的文件排在前邊 -r:結合-l -t使用,倒序排序 例子:顯示跟下有哪些文件 [root@localhost ~]# ls / 1.txt 2.txt bin cgroup etc lib lost+found misc net proc sbin srv tmp var 1.xtx 3.txt boot dev home lib64 media mnt opt root selinux sys usr 黑白顏色是通常文件,藍顏色的是目錄 例子:顯示當前目錄下有哪些文件 #ls ./ #ls (當前位置是./,可是能夠省略) 例子:建立文件並查看文件的詳細信息 [root@localhost tmp]# mkdir book [root@localhost tmp]# touch book/{linux,python,go} [root@localhost tmp]# ls book/ go linux python [root@localhost tmp]# ls -l book/ total 0 -rw-r--r-- 1 root root 0 Apr 12 18:03 go -rw-r--r-- 1 root root 0 Apr 12 18:03 linux -rw-r--r-- 1 root root 0 Apr 12 18:03 python 例子:顯示a.txt的詳細屬性 #ls -l a.txt 例子:顯示book目錄的詳細屬性 [root@localhost tmp]# ls -ld book drwxr-xr-x 2 root root 4096 Apr 12 18:03 book [root@localhost tmp]# cd book/ [root@localhost book]# ls go linux python [root@localhost book]# vi go [root@localhost book]# vi linux [root@localhost book]# vi python [root@localhost book]# ls -l total 12 -rw-r--r-- 1 root root 164 Apr 12 18:11 go -rw-r--r-- 1 root root 83 Apr 12 18:13 linux -rw-r--r-- 1 root root 165 Apr 12 18:13 python ls -lh total 45M -rw-r--r-- 1 root root 164 Apr 12 18:11 go -rw-r--r-- 1 root root 45M Apr 12 19:01 linux -rw-r--r-- 1 root root 98K Apr 12 18:48 python -h只顯示文件的大小,不顯示目錄的大小 例: [root@localhost book]# cd .. [root@localhost tmp]# ls -l -h total 4.0K drwxr-xr-x 2 root root 4.0K Apr 12 19:04 book 顯示目錄的大小用du命令,此處不過多解釋。講解磁盤的時候會詳情講解。 -t將最後修改的文件排在前面 [root@localhost tmp]# cd book/ [root@localhost book]# ls go linux python [root@localhost book]# ls -l total 45676 -rw-r--r-- 1 root root 164 Apr 12 18:11 go -rw-r--r-- 1 root root 46661650 Apr 12 19:01 linux -rw-r--r-- 1 root root 99824 Apr 12 18:48 python [root@localhost book]# vi linux [root@localhost book]# ls -l -t total 45676 -rw-r--r-- 1 root root 46661656 Apr 12 22:27 linux -rw-r--r-- 1 root root 99824 Apr 12 18:48 python -rw-r--r-- 1 root root 164 Apr 12 18:11 go [root@localhost book]# vi go [root@localhost book]# ls -l -t total 45676 -rw-r--r-- 1 root root 167 Apr 12 22:27 go -rw-r--r-- 1 root root 46661656 Apr 12 22:27 linux -rw-r--r-- 1 root root 99824 Apr 12 18:48 python 絕對路徑和相對路徑 絕對路徑:就是從根目錄下開始查找 相對路徑:相對當前位置的路徑 在home目錄下的a中建立一個文件a.txt [root@localhost home]# mkdir a [root@localhost home]# touch /home/a/a.txt 絕對路徑 [root@localhost home]# touch ./a/a.txt 相對路徑(前提必須在home之下) [root@localhost home]# touch a/a.txt 相對路徑(前提必須在home之下) touch ./a/a.txt(前提必須在home之下) touch a/a.txt (前提必須在home之下) 例子:切換到/etc/init.d目錄下 要求1:在init.d下新建目錄abc 要求2:在/etc下新建目錄abc 1:方法1:相對路徑 [root@localhost home]# cd /etc/init.d [root@localhost init.d]# mkdir abc [root@localhost init.d]# ls abc autofs cups kdump netconsole ntpdate rdisc [root@localhost ~]# mkdir /etc/init.d/abc [root@localhost ~]# .ls /etc/init.d/ abc autofs cups kdump netconsole ntpdate rdisc rpcsvcgssd sssd 絕對路徑:mkdir /etc/abc 相對路徑:mkdir ../abc 七、cat命令 全稱:concatenate(鏈接並顯示:拼接多個文件) 做用:顯示一個文本文件中的內容 格式:cat [選項] 文件 選項: -n:在每行的前面顯示行號 361 cat /etc/init.d/halt 362 cat -n /etc/init.d/halt -E:顯示出來行結束符 補充:windows中的文件的換行符:\n linux中的文件的換行符:$ (這樣的符號都是隱性符號-都是默認不可見的) 八、tac命令 做用:將一個文件中的內容倒序顯示出來 (最後一行變成第一行) [root@localhost tmp]# vi 1.txt 11111 2222 3333 444 555 [root@localhost tmp]# tac 1.txt 555 444 3333 2222 11111