Ubuntu 简明教程

Ubuntu - Command Line

Ubuntu 是一个基于 Linux 的操作系统,而大多数 Linux 用户更熟悉命令行界面。在本教程中,我们将介绍在 Ubuntu 中使用的一些流行命令行。

Ubuntu is a Linux based operating system and most Linux users are more familiar with the command line interface. In this chapter, we will go through some of the popular command line’s used in Ubuntu.

Invoking the Command Line

要调用命令行,请转到搜索选项,并在搜索框中输入命令关键字。

To invoke the command line, go to the search option and enter the command keyword in the search box.

invoking command line

搜索结果将显示“终端”选项。双击以获取命令行,如下图所示。

The search result will give the Terminal option. Double-lick to get the command line as shown in the following screenshot.

terminal option

Directory Listing

最容易开始的命令是目录列表命令,用于列出目录内容。

The easiest command to start with, is the directory listing command which is used to list the directory contents.

Syntax

ls –option directoryname

Parameters

  1. Option − These are the options to be specified with the ls command.

  2. Directoryname − This is the optional directory name that can be specified along with the ls command.

Output

输出将是目录内容的列表。

The output will be the listing of the directory contents.

Example

在以下示例中,我们只需发出 ls 命令即可列出目录内容。

In the following example, we just issue the ls command to list the directory contents.

list directory contents

当前目录的目录列表将显示为输出。

The directory listing of the current directory will be shown as the output.

ls 命令的另一种变体是列出目录,但在每行项目上显示更多详细信息。这在以下屏幕截图中使用 ls –l 命令显示。

Another variant of the ls command is to list the directory, but with more details on each line item. This is shown in the following screenshot with the ls –l command.

another variant

Clearing the Screen

为了清除屏幕,我们可以使用 clear 命令。

To clear the screen, we can use the clear command.

Syntax

clear

Parameters

None

Output

命令行屏幕将被清除。

The command line screen will be cleared.

Command Help

若要获取有关命令的更多信息,我们可以使用“ man ”命令。

To get more information on a command, we can use the ‘man’ command.

Syntax

man commandname

Parameters

Commandname - 这是需要更多信息的命令名称。

Commandname − This is the name of the command for which more information is required.

Output

将显示有关命令的信息。

The information on the command will be displayed.

Example

以下是一个“man”命令示例。如果我们发出“ man ls ”命令,我们将获得以下输出。输出将包含有关 ls 命令的信息。

Following is an example of the ‘man’ command. If we issue the ‘man ls’ command, we will get the following output. The output will contain information on the ls command.

command help

Finding For Files

我们可以使用 find 命令查找文件。

We can use the find command to find for files.

Syntax

find filepattern

Parameters

Filepattern - 这是用于查找文件的模式。

Filepattern − This is the pattern used to find for files.

Output

将显示基于文件模式的文件。

The files based on the file pattern will be displayed.

Example

在此示例中,我们将发出以下命令。

In this example, we will issue the following command.

find Sample.*

此命令将列出所有以“Sample”一词开头的文件。

This command will list all the files which start with the word ‘Sample’.

sample

whoami

此命令用于显示当前登录的用户。

This command is used to display who is the current logged on user.

Syntax

whoami

Parameters

None

Output

将显示当前登录用户的名称。

The name of the current logged on user will be displayed.

Example

在此示例中,我们将发出以下命令。

In this example, we will issue the following command.

whoami
whoami

Present Working Directory

此命令将显示当前工作目录。

This command will display the current working directory.

Syntax

pwd

Parameters

None

Output

将显示当前工作目录。

The current working directory will be displayed.

Example

在此示例中,我们将发出以下命令。

In this example, we will issue the following command.

Pwd
present working directory