絕對路徑和相對路徑linux
以跟目錄開始的叫絕對路徑shell
不以根目錄開始的叫絕對路徑bash
[root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg- ifcfg-ens33 ifcfg-lo [root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg- ifcfg-ens33 ifcfg-lo [root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33 [root@cham3 ~]# ls /root/anaconda-ks.cfg /root/anaconda-ks.cfg [root@cham3 ~]# ls /etc/hostname /etc/hostname [root@cham3 ~]# cat /etc/hostname cham3 [root@cham3 ~]# ls /root/.ssh/authorized_keys 絕對路徑 /root/.ssh/authorized_keys [root@cham3 ~]# pwd /root [root@cham3 ~]# ls .ssh/authorized_keys 相對路徑 .ssh/authorized_keys [root@cham3 ~]# cd /etc/sysconfig/ [root@cham3 sysconfig]# ls network-scripts/ifcfg-ens33 network-scripts/ifcfg-ens33 相對路徑
cd命令ssh
[root@cham3 ~]# cd /etc/sysconfig/ cd進入 etc /sysconfig路徑 [root@cham3 sysconfig]# cd - cd - 返回上一次的所在目錄,有點相似電視的返看鍵 /root [root@cham3 ~]# cd - 再cd - 又回到 etc/sysconfig路徑 /etc/sysconfig [root@cham3 sysconfig]# pwd /etc/sysconfig [root@cham3 sysconfig]# cd - /root [root@cham3 ~]# cd ~ ~就是家目錄,cd ~就是回到加目錄 [root@cham3 ~]# cd .. cd .. 返回上一級目錄 [root@cham3 /]# cd - cd- 返回到家目錄 /root [root@cham3 ~]# pwd 查看所在目錄位置
建立和刪除目錄mkdir/rmdir rm命令spa
1.命令語法命令行
rm 目錄code
2.命令描述:排序
rm(remove)的縮寫,這個命令既能夠刪除目錄,也能夠刪除文件。圖片
3.命令參數ip
-r 刪除目錄用的選項,能夠刪除非空目錄。但會詢問你是否刪除,"y" 或 "n"
-f 表示強制刪除。它不會詢問你是否刪除。若是後面跟一個不存在的文件或目錄,則不會報錯。在使用-f選項的時候,必定要加上-r選項,不然會報錯。
注:通常使用-rf命令,這樣刪除目錄或文件比較方便。
1.History命令語法: #history [n]
#history [-c]
#history [-raw] histfiles
2.命令描述: history(歷史的簡寫)能夠列出以前你用的全部命令
3.參數:
n :數字,要列出最近的 n 筆命令列表
-c :將目前的shell中的全部 history 內容所有消除
-a :將目前新增的history 指令新增入 histfiles 中,若沒有加 histfiles , 則預設寫入 ~/.bash_history
-r :將 histfiles 的內容讀到目前這個 shell 的 history 記憶中
-w :將目前的 history 記憶內容寫入 histfiles
Linux系統當你在shell(控制檯)中輸入並執行命令時,shell會自動把你的命令記錄到歷史列表中,通常保存在用戶目錄下的.bash_history文件中。默認保存1000條,你也能夠更改這個值。
若是你鍵入 history, history會向你顯示你所使用的前1000個歷史命令,而且給它們編了號,你會看到一個用數字編號的列表快速從屏幕上捲過。你可能不須要查看1000個命令中的全部項目, 固然你也能夠加入數字來列出最近的 n 筆命令列表。
linux中history命令不單單讓咱們能夠查詢歷史命令而已. 咱們還能夠利用相關的功能來幫咱們執行命令。
列出全部的歷史記錄: # history
只列出最近10條記錄: # history 10 (注,history和10中間有空格)
使用命令記錄號碼執行命令,執行歷史清單中的第99條命令 #!99 (!和99中間沒有空格)
重複執行上一個命令 #!!
執行最後一次以rpm開頭的命令(!? ?表明的是字符串,這個String能夠隨便輸,Shell會從最後一條歷史命令向前搜索,最早匹配的一條命令將會獲得執行。) #!rpm
逐屏列出全部的歷史記錄:# history | more 使用空格看下面的命令記錄。
當即清空history當前全部歷史命令的記錄 #history -c
除了使用history命令,在 shell 或 GUI 終端提示下,你也可使用上下方向鍵來翻閱命令歷史(向下箭頭會向前翻閱),直到你找到所需命令爲止。這可讓咱們很方便地編輯前面的某一條命令,而不用重複輸入相似的命令。
1.命令格式:
#mkdir [-mp]目錄名稱
2.命令描述:
命令mkdir(make directory的簡寫)用於建立目錄。
3.命令參數:
-m:選項用於指定要建立目錄的權限.
-p:選項能夠建立一大串級聯目錄,而且當建立一個已經存在的目錄時,不會報錯。
-pv:加上v選項能夠顯示建立的過程
1.命令格式:
#rmdir 目錄名稱
2.命令功能:
命令rmdir(remove directory的簡寫)用於刪除空目錄,後面能夠是一個目錄,也能夠是多個目錄(用空格分隔)該命令只能刪除目錄,不能刪除文件。
1.命令格式:
touch [選項] [文件]
2.命令描述:
若是有這個文件,則會改變該文件的訪問時間,若是沒有這個文件,就會建立這個文件。
3.命令參數:
-a 或--time=atime或--time=access或--time=use 只更改存取時間。
-c 或--no-create 不創建任何文檔。
-d 使用指定的日期時間,而非如今的時間。
-f 此參數將忽略不予處理,僅負責解決BSD版本touch指令的兼容性問題。
-m 或--time=mtime或--time=modify 只更改變更時間。
-r 把指定文檔或目錄的日期時間,通通設成和參考文檔或目錄的日期時間相同。
-t 使用指定的日期時間,而非如今的時間。
1.命令語法:tree [-aACdDfFgilnNpqstux][-I <範本樣式>][-P <範本樣式>][目錄...]
2.命令描述:以樹狀圖列出目錄的內容。
補充說明:執行tree指令,它會列出指定目錄下的全部文件,包括子目錄裏的文件。
3.命令參數:
-a 顯示全部文件和目錄。
-d 顯示目錄名稱而非內容。
-D 列出文件或目錄的更改時間。
-f 在每一個文件或目錄以前,顯示完整的相對路徑名稱。
-i 不以階梯狀列出文件或目錄名稱。
-N 直接列出文件和目錄名稱,包括控制字符。
-p 列出權限標示。
-s 列出文件或目錄大小。
-t 用文件和目錄的更改時間排序。
如下是命令行:
make directory Last login: Thu Oct 19 18:23:24 2017 from 192.168.230.1 咱們先登錄 [root@cham2 ~]# mkdir /tmp/chamlinux 在tmp下新建一個chamlinux目錄 [root@cham2 ~]# ls -ld /tmp/chamlinux 用ls -ld 查看目錄 drwxr-xr-x 2 root root 6 10月 23 21:18 /tmp/chamlinux [root@cham2 ~]# date 時間 2017年 10月 23日 星期一 21:19:01 CST [root@cham2 ~]# mkdir /tmp/chamlinux/1/2/ 會提示沒有文件或目錄 mkdir: 沒法建立目錄"/tmp/chamlinux/1/2/": 沒有那個文件或目錄 [root@cham2 ~]# ls -l /tmp/chamlinux 看一下 是空的 總用量 0 [root@cham2 ~]# mkdir -p /tmp/chamlinux/1/2/ 用-p 級聯建立 [root@cham2 ~]# ls -l /tmp/chamlinux/ 總用量 0 drwxr-xr-x 3 root root 15 10月 23 21:20 1 [root@cham2 ~]# ls -l /tmp/chamlinux/1 總用量 0 drwxr-xr-x 2 root root 6 10月 23 21:20 2 [root@cham2 ~]# mkdir -p /tmp/chamlinux/2/3/4 [root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/4 -v可視化過程 [root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/4 mkdir: 已建立目錄 "/tmp/chamlinux/2/3" mkdir: 已建立目錄 "/tmp/chamlinux/2/3/4" [root@cham2 ~]# rmdir /tmp/chamlinux/2 rmdir: 刪除 "/tmp/chamlinux/2" 失敗: 目錄非空 [root@cham2 ~]# rmdir /tmp/chamlinux/2/3/4/ [root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt [root@cham2 ~]# ls /tmp/chamlinux/2/3/ 1.txt [root@cham2 ~]# tree /tmp/chamlinux/ /tmp/chamlinux/ ├── 1 │ └── 2 └── 2 └── 3 └── 1.txt 4 directories, 1 file [root@cham2 ~]# rmdir /tmp/chamlinux/2/3 rmdir: 刪除 "/tmp/chamlinux/2/3" 失敗: 目錄非空 [root@cham2 ~]# rmdir /tmp/chamlinux/1/2/ [root@cham2 ~]# mk mkdict mkfifo mkfs.ext2 mkfs.xfs mknod mkdir mkfs mkfs.ext3 mkhomedir_helper mkswap mkdumprd mkfs.btrfs mkfs.ext4 mkinitrd mktemp mke2fs mkfs.cramfs mkfs.minix mklost+found [root@cham2 ~]# mkdir /tmp/chamlinux/1/2 [root@cham2 ~]# rmdir -p /tmp/chamlinux/1/2/ 這種方法不多用 同樣能夠級聯刪除 rmdir: 刪除目錄 "/tmp/chamlinux" 失敗: 目錄非空 [root@cham2 ~]# tree /tmp/chamlinux/ 其實是已經刪除了1/2已經刪除了 /tmp/chamlinux/ └── 2 └── 3 └── 1.txt 2 directories, 1 file [root@cham2 ~]# rm /tmp/chamlinux/2/3/1.txt 使用rm 命令刪除 rm:是否刪除普通空文件 "/tmp/chamlinux/2/3/1.txt"?y [root@cham2 ~]# tree /tmp/chamlinux/ 看一下 /tmp/chamlinux/ └── 2 └── 3 2 directories, 0 files [root@cham2 ~]# toch /tmp/chamlinux/2/3/1.txt 新建文件 -bash: toch: 未找到命令 [root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt 新建文件 [root@cham2 ~]# touch /tmp/chamlinux/2/3/2.txt [root@cham2 ~]# rm /tmp/chamlinux/2/3/ 使用了TAB命令 1.txt 2.txt [root@cham2 ~]# rm /tmp/chamlinux/2/3/ 1.txt 2.txt [root@cham2 ~]# rm /tmp/chamlinux/2/3/*.txt 用*表示通配 rm:是否刪除普通空文件 "/tmp/chamlinux/2/3/1.txt"?n rm:是否刪除普通空文件 "/tmp/chamlinux/2/3/2.txt"?n [root@cham2 ~]# rm -f /tmp/chamlinux/2/3/*.txt 加-f 不詢問 強制的 [root@cham2 ~]# !tree 小知識,上一次最近的tree開頭的命令 tree /tmp/chamlinux/ /tmp/chamlinux/ └── 2 └── 3 2 directories, 0 files [root@cham2 ~]# rm /tmp/chamlinux/2/3/ 刪除目錄rm不行 rm: 沒法刪除"/tmp/chamlinux/2/3/": 是一個目錄 [root@cham2 ~]# rm -rv /tmp/chamlinux/2/3/ 加-r 就是刪除級聯的目錄 rm:是否進入目錄"/tmp/chamlinux/2/3/"? y rm:是否刪除普通空文件 "/tmp/chamlinux/2/3/2.txt"?y 已刪除"/tmp/chamlinux/2/3/2.txt" rm:是否刪除目錄 "/tmp/chamlinux/2/3/"?y 已刪除目錄:"/tmp/chamlinux/2/3/" [root@cham2 ~]# [root@cham2 ~]# rm -r /tmp/chamlinux/2/3/ rm: 沒法刪除"/tmp/chamlinux/2/3/": 沒有那個文件或目錄 [root@cham2 ~]# tree /tmp/chamlinux/ /tmp/chamlinux/ └── 2 1 directory, 0 files [root@cham2 ~]# rm -rf /tmp/chamlinux/2/ 加-f 就是不提示,強制刪除 [root@cham2 ~]# !tree tree /tmp/chamlinux/ /tmp/chamlinux/ 這時候已經沒有任何文件和目錄了 0 directories, 0 files [root@cham2 ~]# !tree tree /tmp/chamlinux/2 /tmp/chamlinux/2 [error opening dir] 0 directories, 0 files [root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/ 在建立一下 mkdir: 已建立目錄 "/tmp/chamlinux/2" mkdir: 已建立目錄 "/tmp/chamlinux/2/3/" [root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt 在新建一個文件 [root@cham2 ~]# touch /tmp/chamlinux/2/2.txt 在新建一個文件 [root@cham2 ~]# tree /tmp/chamlinux/ 看一下 /tmp/chamlinux/ └── 2 ├── 2.txt └── 3 └── 1.txt 2 directories, 2 files [root@cham2 ~]# rm -rfv /tmp/chamlinux/2/3/ 加-v刪除,,是可視化。 已刪除"/tmp/chamlinux/2/3/1.txt" 先刪除文件或者下面的子目錄 已刪除目錄:"/tmp/chamlinux/2/3/" 而後再刪除 [root@cham2 ~]# tree /tmp/chamlinux/ /tmp/chamlinux/ └── 2 └── 2.txt 1 directory, 1 file [root@cham2 ~]# rm -rfv /tmp/chamlinux/2/3/ 知識點刪除一個不存在的目錄,再去刪,什麼 都不提示 -f 起的做用 [root@cham2 ~]# rm -rv /tmp/chamlinux/2/3/ 取消-f rm: 沒法刪除"/tmp/chamlinux/2/3/": 沒有那個文件或目錄