這是用戶在 2024-5-16 19:58 為 https://www.codecademy.com/journeys/back-end-engineer/paths/becj-22-software-engineering-foundations... 保存的雙語快照頁面,由 沉浸式翻譯 提供雙語支持。了解如何保存?
Article
navigation menu

Setting Up Command Line 設置命令行

Navigate your operating system like a professional programmer
像專業程序員一樣導航您的操作系統

Setting Up Your Command Line
設置您的命令行

The command line is a powerful tool used by developers to find, create, and manipulate files and folders. This short tutorial will walk you through the steps for setting up the command line application on your computer.
命令行是開發人員用來查找、創建和操作文件和文件夾的強大工具。這個簡短的教程將引導您完成在您的計算機上設置命令行應用程序的步驟。

Command Line Interfaces (CLIs) come in many forms. The CLI we’ll use is called Bash.
命令行界面(CLI)有很多形式。我們將使用的 CLI 稱為 Bash。

What is Bash? 什麼是 Bash?

Bash, or the __B__ourne-__A__gain __SH__ell, is a CLI that was created over twenty-seven years ago by Brian Fox as a free software replacement for the Bourne Shell. A shell is a specific kind of CLI. Bash is “open source” which means that anyone can read the code and suggest changes. Since its beginning, it has been supported by a large community of engineers who have worked to make it an incredible tool. Bash is the default shell for Linux and Mac. For these reasons, Bash is the most used and widely distributed shell. If you want to learn more about Bash, this Wikipedia article is a good place to start.
Bash,或者__B__ourne-__A__gain __SH__ell,是一个 CLI,由 Brian Fox 在二十七年前创建,作为 Bourne Shell 的自由软件替代品。Shell 是一种特定类型的 CLI。Bash 是“开源”的,这意味着任何人都可以阅读代码并提出更改建议。自诞生以来,它得到了一大群工程师的支持,他们努力使其成为一个令人难以置信的工具。Bash 是 Linux 和 Mac 的默认 shell。因此,Bash 是最常用和广泛分发的 shell。如果您想了解更多关于 Bash 的信息,这篇维基百科文章是一个很好的起点。

Bash Setup for Mac and Windows
为 Mac 和 Windows 设置 Bash

Mac users: Mac 用户:

As mentioned before, Bash is the default shell on Linux and Mac OS X, so good news, you don’t have to install anything!
如前所述,Bash 是 Linux 和 Mac OS X 上的默认 shell,所以好消息是,你不需要安装任何东西!

To access Bash in OS X, you can use an application called Terminal.
要在 OS X 中访问 Bash,您可以使用一个名为 Terminal 的应用程序。

1. First open the Applications folder, then open the Utilities folder.
1. 首先打开“应用程序”文件夹,然后打开“实用工具”文件夹。

2. Once you’re in the Utilities folder you will see the application Terminal. Open the Terminal application and you’re ready to go!
2. 一旦您进入“实用工具”文件夹,您将看到“终端”应用程序。打开“终端”应用程序,您就可以开始了!

3. For ease of access later, you can keep Terminal in your Dock. Simply right click (alt-click) the Terminal icon in your dock, then select “Options”, then “Keep In Dock.”
3. 为了以后更方便访问,您可以将“终端”保留在您的 Dock 中。只需在 Dock 中右键单击(或按住 Option 键单击)“终端”图标,然后选择“选项”,再选择“保持在 Dock 中”。

Continue to the “Try it Out!” section below for some simple first steps with your new tool.
继续阅读下面的“试一试!”部分,了解如何使用您的新工具的一些简单第一步。

Windows users: Windows 用戶:

Windows has a different CLI, called Command Prompt. While this has many of the same features as Bash, Bash is much more popular. Because of the strength of the open source community and the tools they provide, mastering Bash is a better investment than mastering Command Prompt.
Windows 有一個不同的 CLI,稱為命令提示字元。儘管這有許多與 Bash 相同的功能,但 Bash 更受歡迎。由於開源社區的實力和他們提供的工具,精通 Bash 比精通命令提示字元更值得投資。

To use Bash on a Windows computer, we will download and install a program called Git Bash. Git Bash allows us to easily access Bash as well as another tool we’ll be using later called Git, inside the Windows environment.
要在 Windows 電腦上使用 Bash,我們將下載並安裝一個名為 Git Bash 的程式。Git Bash 讓我們可以輕鬆地在 Windows 環境中訪問 Bash,以及稍後將使用的另一個工具 Git。

You can either watch the following video, or read the rest of this article.
您可以觀看以下視頻,或閱讀本文的其餘部分。

How to install Git Bash:
如何安裝 Git Bash:

1. Navigate to the Git Bash installation page and click the Download button. download 2. Once Git Bash is downloaded, run the downloaded .exe file and allow the application to make changes to your PC. You will get a prompt that says “Do you want to allow this app to make changes to your device?” Click Yes.
1. 前往 Git Bash 安裝頁面並點擊下載按鈕。2. 下載 Git Bash 後,運行下載的 .exe 檔案並允許應用程式對您的電腦進行更改。您將收到一個提示,上面寫著“您要允許此應用程式對您的設備進行更改嗎?”點擊“是”。


3. To keep things simple, we will use the default settings for everything in this installation, so all you need to do now is keep clicking Next, and finally Finish. setup 4. Open the Start menu by clicking on the Windows icon and typing “Git Bash” into the search bar. The icon for Git Bash and the words “Git Bash Desktop App” will appear. Click on the icon or the words “Git Bash Desktop App” to open Git Bash. openGitBash 5. A new window will open. This is the Git Bash CLI where we will run Bash commands. Whenever a new window of the Git Bash app is opened, you will always be placed in the same directory, your home directory.
為了保持簡單,我們將在此安裝中使用默認設置,所以您現在只需要不斷點擊「下一步」,最後點擊「完成」。打開「開始」菜單,點擊 Windows 圖標並在搜索欄中輸入“Git Bash”。將出現 Git Bash 圖標和“Git Bash 桌面應用程序”字樣。點擊圖標或“Git Bash 桌面應用程序”字樣以打開 Git Bash。將打開一個新窗口。這是 Git Bash CLI,我們將在其中運行 Bash 命令。每次打開 Git Bash 應用程序的新窗口時,您將始終位於相同目錄,即您的主目錄。

The home directory is represented by the tilde sign, ~, in the CLI after MINGW64. The tilde is another way to say /c/Users/username in Git Bash or C:\home\Users\username in Windows’ Command Prompt.
家目錄在 CLI 中以波浪號 ~ 代表。在 MINGW64 後,波浪號是 Git Bash 或 Windows 命令提示字元中表示 /c/Users/username 的另一種方式。

The absolute path of your current working directory, how you got from the root directory to the directory you are currently in, will always be noted at the top of the window:
您當前工作目錄的絕對路徑,您從根目錄到當前目錄的路徑,將始終顯示在窗口頂部:

homeDirectory

Git Bash works by giving you a CLI that acts like a Bash CLI. That means you can now work with your files and folders using Bash commands instead of Windows commands.
Git Bash 通過提供一個類似 Bash CLI 的 CLI 來工作。這意味著您現在可以使用 Bash 命令而不是 Windows 命令來處理文件和文件夾。

Congratulations, you now have Bash installed on your computer, ready to use!
恭喜,您現在已在計算機上安裝了 Bash,可以隨時使用!

Try it out! 試試看吧!

Now that you have your Command Line Interface open on your desktop, you are ready to use it. Go ahead and try some of the commands on your personal computer. Here are some good commands for practice:
現在您已經在桌面上打開了您的命令行界面,可以開始使用它了。Go嘗試在您的個人電腦上運行一些命令。這裡有一些練習用的好命令:

  1. ls to list the contents of the current directory. It may look something like this:
    ls 以列出當前目錄的內容。它可能看起來像這樣:
$ ls
Applications                Pictures
Codecademy                Public
Desktop                     Downloads
Documents                   Library

  1. mkdir test to make a new directory named test. Now, when you type ls you should see a folder called test:
    使用 mkdir test 命令來創建一個名為 test 的新目錄。現在,當您輸入 ls 時,您應該會看到一個名為 test 的文件夾:
$ ls
Applications                Pictures
Codecademy                Public
Desktop                     Downloads
Documents                   Library
test

  1. cd test to navigate into the new directory. You won’t see an output when you do this.
    cd test 進入新目錄。這樣做時不會看到輸出。
  2. echo "Hello Command Line" >> hello_cli.txt to create a new file named hello_cli.txt and add Hello Command Line to that file. When you type ls, you should see the following:
    使用 echo "Hello Command Line" >> hello_cli.txt 來創建一個名為 hello_cli.txt 的新檔案,並將 Hello Command Line 添加到該檔案中。當您輸入 ls 時,您應該看到以下內容:
$ ls
hello_cli.txt

  1. cat hello_cli.txt to print the contents of the hello_cli.txt file to the terminal. You should see something like:
    cat hello_cli.txt 列印 hello_cli.txt 檔案的內容到終端機。您應該會看到類似以下的內容:
$ cat hello_cli.txt
Hello Command Line

Good job! You’re ready to explore the world of the Command Line Interface on your own computer.
做得好!您已經準備好在自己的電腦上探索命令列介面的世界。