# 我的linux日常生活-8.常用指令 ###### tags: `我的linux日常生活` 學習Linux 當中,用圖形界面是我依開始接觸的起步方式,但是我當初會接觸Linux 的原因是工作關係,加上在網路上的資源大多數是以CLI 為操作界面,所以如何透過文字界面操作就變成我在學習路上必經的過程。 其實,在處理一些重複的事情,透過指令方式會比透過圖形界面來的有效率,例如:上傳檔案到不同的主機上。前提得學會如何下指令,接下來這邊就介紹在日常生活中常用的指令。 ## 登入系統 cd 在Linux 世界中,登入方式很長透過SSH 服務登入,指令如下: ```ssh= # ssh [userName]@[ip] -p [port] jameschang@JamesChangNB:~$ ssh pollochang@192.168.56.3 -p 22 pollochang@192.168.56.3's password: ``` **ssh** 就是只透過 ssh 協定連接要遠端的主機 **pollochang** 就是使用者帳號 **192.168.56.3** 是你要登入主機的IP **-p 22** 指透過阜號 22 登入,不過這邊通常不用特別定,預設就是22 port。 按下 enter 之後就會進行登入,有連接成功後對方的系統就會要求你輸入登入密碼啦~ 登入成功就會進入這個畫面 ```shell ****Linux pollochangWorking 4.19.0-17-amd64 #1 SMP Debian 4.19.194-2 (2021-06-21) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Fri Jun 25 17:58:40 2021 from 192.168.56.1 pollochang@pollochangWorking:~$ ``` ## 打開目錄 cd 登入主機後,系統會自動到使用者的家目錄。 ``` pollochang@pollochangWorking:~$ ``` 輸入 `pwd` 就可以知道你目前的絕對路徑 ```shell= pollochang@pollochangWorking:~$ pwd pollochang@pollochangWorking:~$ /home/pollochang ``` 假設今天有個文件在`下載`目錄底下 ```shell /home/pollochang/下載/ ``` 則可以輸入下列指令到達 ```shell pollochang@pollochangWorking:~$ cd 下載 pollochang@pollochangWorking:~$ cd ~/下載 pollochang@pollochangWorking:~$ cd /home/pollochang/下載/ ``` 上面三個指令雖然達到的目的雖然是相同,但是方法卻不同。 還記得剛剛一開始登入的絕對路徑是 ```shell /home/pollochang ``` 而`下載`的絕對路徑是 ```shell /home/pollochang/下載/ ``` 第一個方式是在`目前`的路徑下開啟`下載`。 第二個方式是在`家目錄`下開啟`下載`。小蚯蚓[~]符號代表家目錄的意思。 第三個方式則是從`根目錄`依敘述路徑開啟`下載`。 會介紹這三種方式,主要是在如果有機會寫腳本記得,有下`cd`指令時記得用`絕對路徑`描述要開啟的資料夾,不然腳本檔很有可能會在執行的過程中發生錯誤。 ## 檢視目錄內容 ls 進入到下載的目錄中,我們想要知道目錄底下有哪些檔案時就可已透過`ls`知道 ```terminal pollochang@pollochangWorking:~$ ls 1624615269877.pdf zxing-j2se-1.7.zip ``` 另外,`ll`可以提供檔案使用權限 更動資訊等詳細資訊 ```terminal pollochang@pollochangWorking:~$ ls 總計 12341 -rw-r--r-- 1 pollochang pollochang 1818 6月 25 18:01 test.txt -rw-r--r-- 1 pollochang pollochang 1818 6月 25 18:11 zxing-j2se-1.7.zip ``` 以上就是對於目錄長操作的指令,接下來會針對檔案介紹幾個常用的指令。