標籤:mkdir cd ls linux 命令列
接下來我們就來看幾個常見的處理目錄的命令吧:
ls: 列出目錄
cd:切換目錄
pwd:顯示目前的目錄
mkdir:建立一個新的目錄
rmdir:刪除一個空的目錄
cp: 複製檔案或目錄
rm: 移除檔案或目錄
mv (移動檔案與目錄,或修改名稱)
你可以使用 man [命令] 來查看各個命令的使用文檔,如 :man cp。
ls (列出目錄)
選項與參數:
-a :全部的檔案,連同隱藏檔( 開頭為 . 的檔案) 一起列出來(常用)
-d :僅列出目錄本身,而不是列出目錄內的檔案資料(常用)
-l :長資料串列出,包含檔案的屬性與許可權等等資料;(常用)
<span style="font-size:14px;">[email protected]:~$ lsdump examples.desktop 公用的 視頻 文檔 音樂erh-mongo-munin-08e7aeb tech163 模板 圖片 下載 案頭[email protected]:~$ ls -l總用量 56drwxrwxr-x 6 deng deng 4096 6月 9 17:56 dumpdrwxrwxr-x 3 deng deng 4096 2月 24 2012 erh-mongo-munin-08e7aeb-rw-r--r-- 1 deng deng 8445 6月 6 09:21 examples.desktopdrwxrwxr-x 3 deng deng 4096 6月 10 08:35 tech163drwxr-xr-x 2 deng deng 4096 6月 6 11:19 公用的drwxr-xr-x 2 deng deng 4096 6月 6 11:19 模板drwxr-xr-x 2 deng deng 4096 6月 6 11:19 視頻drwxr-xr-x 2 deng deng 4096 6月 6 11:19 圖片drwxr-xr-x 5 deng deng 4096 6月 9 17:25 文檔drwxr-xr-x 3 deng deng 4096 6月 11 09:51 下載drwxr-xr-x 2 deng deng 4096 6月 6 11:19 音樂drwxr-xr-x 2 deng deng 4096 6月 11 10:23 案頭[email protected]:~$ ls -a. .gksu.lock .rpmdb.. .gnome2 .sunpinyin.adobe .goutputstream-0D97ZX tech163.bash_history .goutputstream-SYQVZX .thumbnails.bash_logout .goutputstream-XWFPZX .viminfo.bashrc .gstreamer-0.10 .Xauthority.cache .gtk-bookmarks .xinputrc.compiz-1 .gvfs .xsession-errors.config .ICEauthority .xsession-errors.old.dbshell .java 公用的.dbus .local 模板.dmrc .macromedia 視頻dump .mission-control 圖片erh-mongo-munin-08e7aeb .mozilla 文檔examples.desktop .pip 下載.fontconfig .profile 音樂.freemind .pulse 案頭.gconf .pulse-cookie</span>
cd (切換目錄)
<span style="font-size:14px;"> cd [相對路徑或絕對路徑]</span>
<span style="font-size:14px;">[email protected]:~$ mkdir jingdong[email protected]:~$ cd jingdong[email protected]:~/jingdong$ cd .. #返回上一層檔案夾[email protected]:~$ cd /home/deng/tech163[email protected]:~/tech163$ cd - #相當於文檔中的Ctrl+Z,復原/home/deng[email protected]:~$ cd / #返回根目錄</span>
pwd (顯示目前所在的目錄)選項與參數:-P :顯示出確實的路徑,而非使用連結 (link) 路徑。
mkdir (建立新目錄)
<span style="font-size:14px;">mkdir [-mp] 目錄名稱</span>
選項與參數:
-m :設定檔的許可權喔!直接配置,不需要看預設許可權 (umask) 的臉色~
-p :協助你直接將所需要的目錄(包含上一級目錄)遞迴建立起來!
rmdir (刪除空的目錄)選項與參數:
-p :連同上一級『空的』目錄也一起刪除
cp (複製檔案或目錄)
<span style="font-size:14px;">cp [-adfilprsu] 來源檔(source) 目標檔(destination)cp [options] source1 source2 source3 .... directory</span>
選項與參數:
-a :相當於 -pdr 的意思,至於 pdr 請參考下列說明;(常用)
-d :若來源檔為連結檔的屬性(link file),則複製連結檔屬性而非檔案本身;
-f :為強制(force)的意思,若目標檔案已經存在且無法開啟,則移除後再嘗試一次;
-i :若目標檔(destination)已經存在時,在覆蓋時會先詢問動作的進行(常用)
-l :進行硬式連結(hard link)的連結檔建立,而非複製檔案本身;
-p :連同檔案的屬性一起複製過去,而非使用預設屬性(備份常用);
-r :遞迴持續複製,用於目錄的複製行為;(常用)
-s :複製成為符號連結檔 (symbolic link),亦即『捷徑』檔案;
-u :若 destination 比 source 舊才升級 destination !
rm (移除檔案或目錄)
<span style="font-size:14px;">rm [-fir] 檔案或目錄</span>
選項與參數:
-f :就是 force 的意思,忽略不存在的檔案,不會出現警告資訊;
-i :互動模式,在刪除前會詢問使用者是否動作
-r :遞迴刪除啊!最常用在目錄的刪除了!這是非常危險的選項!!!
mv (移動檔案與目錄,或修改名稱)
<span style="font-size:14px;">mv [-fiu] source destinationmv [options] source1 source2 source3 .... directory</span>
選項與參數:
-f :force 強制的意思,如果目標檔案已經存在,不會詢問而直接覆蓋;
-i :若目標檔案 (destination) 已經存在時,就會詢問是否覆蓋!
-u :若目標檔案已經存在,且 source 比較新,才會升級 (update)
linux處理目錄的常用命令