練習背景: 您的主目錄中累積了幾個檔案,您決定對其進行整理。您計劃建立多個新子目錄,并來回複制和移動您的檔案以适合您的新架構。此外,您必須删除完全不需要的多個檔案。
練習目标: 通過将檔案放置于相應的子目錄中,主目錄更加整齊有序。
練習說明:
1. 使用密碼 student 以使用者 student 身份登入。如果您正在使用圖形環境,請通過依次單擊應用程式->附件->終端啟動終端。
2. 登入系統後,您應立即位于主目錄中。使用“列印工作目錄”指令驗證這一點。[student@stationX ~]$ pwd
/home/student
3. 使用以下指令之一檢視您的主目錄中是否包含任何檔案:
ls
ls -a
ls -al
為什麼第一條和第二條指令傳回的檔案數量不同?
根據第三條指令的報告,目前您主目錄中最大檔案的大小是多少?
4. 現在您将使用 touch 建立此序列所需的檔案。後續單元将介紹擴充如何在以下指令中使用的詳細資訊。現在,隻需如您看到的那樣準确鍵入以下行(使用大括号 {},并在前兩組集合之間插入下劃線):
[student@stationX ~]$ touch {report,graph}_{jan,feb,mar}
5. 使用 ls 指令可檢視之前指令的結果。您應該會發現,您的主目錄中已建立以下六個新的空檔案。
[student@stationX ~]$ ls
graph_feb graph_jan graph_mar report_feb report_jan report_mar
這些檔案表示您将在餘下的序列中使用的資料檔案。如果由于某種原因您未看到這些檔案,請向講師尋求幫助;如果缺少這些檔案,此實驗的其餘部分将無法正常工作。
6. 為了整理您的檔案,您必須先建立一些新目錄。使用 mkdir 建立幾個目錄。因為您更改了目錄(如下所示),務必檢視您的工作目錄符合預期。
[student@stationX ~]$ mkdir Projects
[student@stationX ~]$ mkdir Projects/graphs
[student@stationX ~]$ cd Projects
[student@stationX Projects]$ mkdir reports
[student@stationX Projects]$ cd reports
[student@stationX reports]$ mkdir ../Backups
使用 ls 檢視您的工作:
[student@stationX reports]$ cd
[student@stationX ~]$ ls -l
total 4
drwxr-xr-x 1 student student 0 Sep 30 21:07 Desktop
-rw-rw-r-- 1 student student 0 Sep 30 21:08 graph_feb
-rw-rw-r-- 1 student student 0 Sep 30 21:08 graph_jan
-rw-rw-r-- 1 student student 0 Sep 30 21:08 graph_mar
drwxrwxr-x 5 student student 4096 Sep 30 21:09 Projects
-rw-rw-r-- 1 student student 0 Sep 30 21:08 report_feb
-rw-rw-r-- 1 student student 0 Sep 30 21:08 report_jan
-rw-rw-r-- 1 student student 0 Sep 30 21:08 report_mar
[student@stationX ~]$ ls Projects
Backups graphs reports
7. 先将所有圖形檔案移動到項目目錄的圖形子目錄。這一操作分為以下兩個步驟:第一步是移動一個檔案;第二步是移動兩個檔案:
[student@stationX ~]$ mv graph_jan Projects/graphs
[student@stationX ~]$ mv graph_feb graph_mar Projects/graphs
[student@stationX ~]$ ls -l Projects/graphs/
total 3
8. 接下來,将兩個“報告”檔案移動到項目目錄的報告子目錄中。使用一個指令移動這些檔案:
[student@stationX ~]$ mv report_jan report_feb Projects/reports
[student@stationX ~]$ ls -l Projects/reports
total 2
9. 删除其餘的報告檔案:
[student@stationX ~]$ rm report_mar
Desktop
Projects
10. 更改為 Backups 目錄并将一月的檔案複制到此目錄。使用絕對路徑名稱複制一個,使用相對路徑名稱複制另一個:
[student@stationX ~]$ cd Projects/Backups
[student@stationX Backups]$ pwd
/home/student/Projects/Backups
[student@stationX Backups]$ cp ../reports/report_jan .
[student@stationX Backups]$ cp
/home/student/Projects/graphs/graph_jan .
[student@stationX Backups]$ ls -l
-rw-rw-r-- 1 student student 0 Sep 30 21:20 graph_jan
-rw-rw-r-- 1 student student 0 Sep 30 21:20 report_jan
尾部點是目标:目前的工作目錄。
11. 通過運作 exit 指令可登出或關閉您的圖形終端。
http://www.51rhca.com/archives/137