Exemplar: Get help in the command line
範例:在命令行中獲取幫助
Activity overview 活動概述
As a security analyst, you won’t have all the answers all the time, but you can learn where to find them. One of the great things about Linux is that you can get help right through the command line.
作為一名安全分析師,你不會總是擁有所有答案,但你可以學習到在哪裡找到它們。Linux 的一大優點是你可以直接通過命令行獲得幫助。
In this lab activity, you’ll use the man and whatis commands to get information on other commands and how they work. You’ll also use the apropos command to search the manual page for a command with a specified string.
在這個實驗活動中,你將使用 man 和 whatis 命令來獲取其他命令的信息及其工作原理。你還將使用 apropos 命令來搜索包含指定字串的命令手冊頁面。
When working as a security analyst, you'll likely find it useful to know how to discover which command to use or information about what commands do.
作為一名安全分析師,了解如何發現應該使用哪個命令或命令的功能信息可能會對你很有幫助。
With that in mind, let’s explore your scenario.
考慮到這一點,讓我們來探討你的情境。
This exemplar is a walkthrough of the previous Qwiklab activity, including detailed instructions and solutions. You may use this exemplar if you were unable to complete the lab and/or you need extra guidance in competing lab tasks. You may also refer to this exemplar to prepare for the graded quiz in this module.
此範例是對之前 Qwiklab 活動的逐步講解,包括詳細的指導和解決方案。如果您無法完成實驗室活動和/或需要額外的指導來完成實驗室任務,可以使用此範例。您也可以參考此範例來準備本模組中的評分測驗。
Scenario 情境
In this scenario, you have to find more information about commands that you need to use. You also need to discover which command to use to perform a certain task.
在這個情境中,你需要尋找更多關於你需要使用的命令的信息。你還需要找出使用哪個命令來執行某個特定任務。
Here’s how you’ll do this task: First, you’ll explore a few commands you can use in the shell to learn more about other commands. Next, you’ll find an option you need to add to a command. Third, you’ll use a command to get a brief description of commands so you can identify their differences. Finally, you’ll identify the command you need to perform a task.
以下是您將完成此任務的方法:首先,您將探索一些可以在 shell 中使用的命令,以便了解更多關於其他命令的資訊。接下來,您將找到需要添加到命令中的選項。第三,您將使用一個命令來獲取命令的簡短描述,以便識別它們的差異。最後,您將識別出需要執行任務的命令。
It's time to get ready to explore some of the Linux help resources!
是時候準備探索一些 Linux 的幫助資源了!
Task 1. Learn more about commands
任務 1. 了解更多關於命令的資訊
In this task, you need to explore a few commands you can use in the shell to learn more about the functionality of other commands.
在此任務中,您需要探索一些可以在 shell 中使用的命令,以了解其他命令的功能。
First, imagine you can’t quite remember what the cat command does and want a quick reminder.
首先,假設您不太記得 cat 命令的作用,並希望快速提醒一下。
Run the whatis command to get a short description of cat
運行 whatis 命令以獲取 cat 的簡短描述.
The command to complete this step:
完成此步驟的指令:
What are the first two words of the short description of cat returned by whatis?
whatis 返回的 cat 簡短描述的前兩個字是什麼?
Answer: The first two words of the short description returned are “concatenate files”.
答案:返回的簡短描述的前兩個字是「連接文件」。
Next, imagine that you want more details about cat and all of its options.
接下來,假設你想要了解更多關於 cat 及其所有選項的細節。
Use the man command to get more details about cat
使用 man 命令來獲取有關 cat 的更多細節.
The command to complete this step:
完成此步驟的指令:
The man command returns a general description of cat and information about each of its options:
man 命令返回 cat 的一般描述以及其每個選項的資訊:
When the first page of information returned by man is displayed, the output pauses.
當 man 返回的第一頁信息顯示時,輸出會暫停。
Note: You can output more information one line at a time by pressing the ENTER key or output the next page of the manual by pressing the space bar.
注意:你可以按下 ENTER 鍵一次輸出更多信息,或者按下空格鍵輸出手冊的下一頁。
What option can you use to number the output lines of the cat command?
您可以使用什麼選項來為 cat 命令的輸出行編號?
Answer: The -n,--number option numbers all the output lines.
答案:-n,--number 選項會為所有的輸出行編號。
3. Press Q to exit this manual page.
3. 按 Q 退出此手冊頁面。
Now, imagine you’ve remembered there’s a command that prints just the first part of a file, but you can’t remember the exact command. The apropos command is useful in these instances. You can use keywords with apropos to find a command.
現在,想像一下你記得有一個命令可以只打印文件的第一部分,但你記不起確切的命令。在這種情況下,apropos 命令非常有用。你可以使用 apropos 搭配關鍵字來找到命令。
4. Use apropos to find a command that returns the first part of a file:
4. 使用 apropos 來找到一個返回文件第一部分的命令:
Note: There is no right and wrong when using apropos in terms of keywords. Think of it as a very focused search. It will only return commands that correspond to keywords you supply. Keep trying if the first returned command does not provide what you need. Also, keep in mind that using the -a option will limit results to only those commands that match all keywords supplied.
注意:使用 apropos 時,關鍵字並沒有對錯之分。可以將其視為一種非常專注的搜尋。它只會返回與您提供的關鍵字相對應的命令。如果第一個返回的命令沒有提供您所需的內容,請繼續嘗試。此外,請記住,使用 -a 選項將限制結果僅為符合所有提供關鍵字的命令。
Which command returns the first part of a file?
哪個命令返回檔案的第一部分?
Answer: The head command returns only the first part of a file.
答案:head 命令僅返回檔案的第一部分。
Task 2. Explore the useradd command
任務 2. 探索 useradd 命令
In this task, imagine that you want to set the expiration date for a temporary user account. You know that you need to use the useradd command for this, but you’re not quite sure how to complete the task. You realize it might involve adding an option to the command.
在此任務中,假設您想要設定臨時使用者帳戶的到期日期。您知道需要使用 useradd 指令,但不太確定如何完成此任務。您意識到這可能涉及在指令中添加一個選項。
Use the most appropriate Linux command to get help on the useradd command and learn more about all of its options.
使用最合適的 Linux 指令來獲取 useradd 指令的幫助,並了解其所有選項的更多資訊。
The command to complete this step:
完成此步驟的指令:
Note: You can output more information one line at a time by pressing the ENTER key or output the next page of the manual by pressing the space bar.
注意:您可以按下 ENTER 鍵逐行輸出更多資訊,或按下空白鍵輸出手冊的下一頁。
Which option can be used with the useradd command to set an expiration date for a temporary user account?
使用 useradd 命令時,哪個選項可以用來設置臨時用戶帳戶的到期日期?
Answer: The -e option can be used to set an expiration date for a temporary user account.
答案:-e 選項可用於為臨時用戶帳戶設置到期日期。
2. Press Q to exit this manual page.
按 Q 退出此手冊頁面。
Task 3. Explore the rm and rmdir commands
任務 3. 探索 rm 和 rmdir 命令
In this task, you need to determine the difference between the rm and rmdir commands.
在此任務中,您需要確定 rm 和 rmdir 命令之間的區別。
Imagine that you’ve used these commands before, but you can’t remember how they’re different.
想像一下,您之前使用過這些命令,但無法記住它們有何不同。
Use the most appropriate Linux command to quickly remind yourself what each command does.
使用最合適的 Linux 指令來快速提醒自己每個指令的功能。
Note: This task will require entering two commands, one with rm and one with rmdir
注意:此任務需要輸入兩個指令,一個是 rm,另一個是 rmdir.
The commands to complete this step:
完成此步驟的指令:
Which of these commands removes only empty directories?
以下哪個命令僅刪除空目錄?
Answer: The rmdir command removes only empty directories.
答案:rmdir 指令僅刪除空目錄。
Task 4. Determine which command to use
任務 4. 確定要使用的指令
In this task, imagine that you need to create a new group but you can’t remember what command to use. You need to identify a command that will do this by searching for it through keywords. In this case, use the keywords create new group
在此任務中,假設您需要創建一個新群組,但您不記得要使用什麼指令。您需要通過關鍵字搜尋來識別可以執行此操作的指令。在這種情況下,使用關鍵字「create new group」.
Use the most appropriate Linux command with these keywords to identify what command to use.
使用這些關鍵字中最合適的 Linux 指令來識別要使用的指令。
The correct command to solve this step:
解決此步驟的正確指令:
What command can you use to create a new group?
您可以使用什麼指令來創建一個新群組?
Answer: The groupadd can be used to create a new group.
答案:可以使用 groupadd 來建立一個新群組。
Conclusion 結論
Great work! 做得好!
You now have practical experience in using basic Linux Bash shell commands to
您現在已經有使用基本 Linux Bash shell 命令的實際經驗來
get a short description of a command,
獲取命令的簡短描述,display the man pages for a command, and
顯示命令的 man 頁面,以及find commands based on keywords about their function.
根據功能的關鍵字查找命令。
This ability will be valuable as you navigate the Linux command line.
當你在使用 Linux 命令行時,這項能力將非常有價值。