Merge pull request #5061 from geekpi/master

translating
This commit is contained in:
geekpi 2017-01-25 10:19:03 +08:00 committed by GitHub
commit c5e18968ff
2 changed files with 105 additions and 96 deletions

View File

@ -1,96 +0,0 @@
LFCS Command Line Basics
=======================
There are quite a few command line basics to cover in this article. We will go over the TeleTYpe (TTY) and a few commands with operators. Be sure to practice all of these and be aware that these are the same for CentOS and Ubuntu unless otherwise noted.
**TTY**
The TTY is used in Linux when there is no Graphical User Interface (GUI) running or when the user is outside of the GUI. TTY is also used when a terminal window is opened, but these are different types of TTY.
There are three types of TTYs:
1. Physical
2. Local Pseudo
3. Remote Pseudo
Basically, each Linux system has around six or seven Physical TTYs. These are accessible by holding down a CTRL+ALT key and pressing F1 through F6 for CentOS and CTRL+ALT and F1 through F7 for Ubuntu.
**NOTE: **Some distros might have a different number of TTYs and different defaults for the GUI. Some distros may have a different key combination of CTRL+F# or ALT+F# to change between the Physical TTYs. When using VirtualBox use the Right CTRL key unless you have changed the Host key.
In CentOS the GUI will be on TTY 1 (CTRL+ALT+F1) and the other Physical TTYs are text based. On Ubuntu the GUI is on TTY 7 (CTRL+ALT+F7) and the other Physical TTYs are text based.
**NOTE:** It is not wise to attempt to load the GUI under another TTY since this can use up a lot of resources, but it is possible.
When Linux starts up, whether CentOS or Ubuntu, the default TTY is opened. If a GUI is installed then it goes to TTY1 for CentOS and TTY7 for Ubuntu. If you open a Terminal window (Pseudo TTY) and use the command 'who' you will see a listing of TTYs in use. An example is shown in Figure 1.
![Figure 01.jpg](https://www.linuxforum.com/attachments/figure-01-jpg.93/)
**FIGURE 1**
In Figure 1 you can see that I am currently logged in to TTY1 (non-GUI). The second line of connections show that I am logged in to the GUI (TTY7) as well as two Pseudo TTYs (PTS/1 and PTS/2). Looking at Figure 2 you can see that the new entry shows a Remote Pseudo TTY (PTS/3). The Remote Pseudo connection is from a system with the IP address of 192.168.0.11.
![Figure 02.jpg](https://www.linuxforum.com/attachments/figure-02-jpg.94/)
**FIGURE 2**
Remote TTY connections can be made with applications such as 'PuTTY' or any SSH Client (if SSH is enabled on the remote Linux system).
If a terminal window has small fonts you can use the keys CTRL+SHIFT and the '+' to enlarge the fonts. Press it multiple times to make it even bigger each time. To shrink it down in size use the CTRL+- to continually make it smaller. To make the terminal font back to the original size press CTRL+0.
**NOTE:** Be aware that the font will only get so large or so small before the key combination will not work anymore.
Hopefully you now understand the various type of TTYs. Let's look at some of the commands which can be used in a TTY.
**Commands**
One of the commands was already discussed previously. The command 'who' is used to show who is logged onto a system.
Another command is 'pwd'. The command 'pwd' stands for 'Print Working Directory'. The command returns the current directory in which you are located. For example, if the terminal prompt is '[jbuse@localhost ~]$' the username is 'jbuse' and the current directory is ~. The tilde (~) designates the user's home folder. The home folder should be '/home/_username_'. The username is the name used to log into the system.
To list the contents of the current folder use the command 'ls'. The 'ls' command stands for List. If no options are specified then the current folder is listed. If you give a folder name then the contents of that folder is listed. For example, to see the contents of the contents of the 'media' folder you would use the command 'ls /media'.
Along with the 'ls' command are a few options we can add to show more detail or specific details. If you wish to see all folder and files, even the hidden ones, use the option '-a'. To see all files and folders in the current directory use the command 'ls -a'. Hidden files and folders will appear with a period in front of the name.
To see a forward slash (/) after each folder name use the option '-F'. A listing of the current folder would be 'ls -F'. The '-F' is used to classify the files by file type. Symbolic links are signified by '@' after the folder name.
You can put the two together to have a command of 'ls -aF'.
**NOTE:** Some options may be of different cases. The options can be case-sensitive.
Another option is the '-l' for a long listing. A sample output is shown in Figure 3\. The folder and file names are listed to the right side. The files are colored white, the folders are dark blue and the symbolic links are light blue. As you can see in Figure 3 the symbolic link 'vtrgb' is linked from '/etc/alternatives/vtrgb'.
![Figure 03.jpg](https://www.linuxforum.com/attachments/figure-03-jpg.95/)
**FIGURE 3**
The first column to the left is the permissions for the file or folder. The first letter is either a 'd' for directory or a '-' for a file. The next three letters show permissions for the owner ('r' read, 'w' write and 'x' execute) followed by the group permissions and permissions for 'others'. The next column of numbers shows the number of links to the file or folder. The next column is the owner name followed by the group name of ownership. The next column is the number of bytes which the file or folder takes up on the storage device. The next three columns are the month, day and year the file was last modified. Finally, the final column is the path name.
So far you have seen that the listing is sorted alphabetically. To reverse the order from 'z to a' and not 'a to z' use the '-r' option. The '-r' or reverse option causes the ls command to reverse the output order.
To list the files by the modified timestamp use the '-t' option. The order is from the most recently modified to the oldest modification date. Of course to reverse the order use both the '-t' and the '-r' together in the command 'ls -tr'.
If you do not like looking at the long number of bytes which the file takes up use the option '-h'. The output will be more readable such as '4.0K' and not '4096'.
To get specific information on a single folder use the option '-d', but the folder must be specified. For example to see the specifics for the folder '/media' use the command 'ls -ld /media'.
Another command to be familiar with is the command 'cat'. The command 'cat' is used to copy a standard input (a file) to the standard output (the screen). Use 'cat' to easily view the contents of a file. For example to see the contents of a file called 'text' use the command 'cat text' if you are in the same folder as the file 'text'. If you are not in the same folder then you must specify the location. For example, if the file 'text' is in the folder '/home/jarret/test/' then the command would be 'cat /home/jarret/test/text'.
Another very useful command is 'man'. The 'man' command is used to view documentation for specific commands. For example, to see the MANual pages for the command 'ls' use the command 'man ls'.
**NOTE:** Remember that on the LFCS exam you have access to the 'man' command and can use it.
Look over these commands and test them out to be familiar with them. Use the 'man' command and look over the commands covered in this article to see what other options are available.
**NOTE:** I tend to use the word 'options' for the characters passed to a command to change its function or output. Some people may use the words 'parameters', 'arguments' and the like. They tend to be interchangeable.
--------------------------------------------------------------------------------
via: https://www.linuxforum.com/threads/lfcs-command-line-basics.3334/
作者:[Jarret][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linuxforum.com/members/jarret.268/

View File

@ -0,0 +1,105 @@
LFCS 命令行基础
=======================
本文中包含了很多命令行基础。我们将讨论TeleTYpeTTY和几个带有操作符的命令。确保做完所有练习并要知道除非另有说明对 CentOS 和 Ubuntu 都是相同的。
**TTY**
当没有图形用户界面GUI或当用户在 GUI 之外时 TTY 会在 Linux 中使用。当打开终端窗口时也使用 TTY但这些是不同类型的TTY。
有三种类型的TTY
1. 物理终端
2. 本地伪终端
3. 远程伪终端
基本上,每个 Linux 系统有大约六个或七个物理 TTY。 通过按住 CTRL + ALT 键,然后在 CentOS 按住 F1 到 F6 ,在 Ubuntu 中按住 CTRL + ALT 和 F1 到 F7。
**NOTE: **Some distros might have a different number of TTYs and different defaults for the GUI. Some distros may have a different key combination of CTRL+F# or ALT+F# to change between the Physical TTYs. When using VirtualBox use the Right CTRL key unless you have changed the Host key.
In CentOS the GUI will be on TTY 1 (CTRL+ALT+F1) and the other Physical TTYs are text based. On Ubuntu the GUI is on TTY 7 (CTRL+ALT+F7) and the other Physical TTYs are text based.
**NOTE:** It is not wise to attempt to load the GUI under another TTY since this can use up a lot of resources, but it is possible.
When Linux starts up, whether CentOS or Ubuntu, the default TTY is opened. If a GUI is installed then it goes to TTY1 for CentOS and TTY7 for Ubuntu. If you open a Terminal window (Pseudo TTY) and use the command 'who' you will see a listing of TTYs in use. An example is shown in Figure 1.
**注意:** 发行版可能有不同数量的 TTY 和不同的 GUI 默认值。发行版可能具有如 CTRL + F 或 ALT + F 的不同的键组合在物理 TTY 之间改变。当使用 VirtualBox 时,除非您更改了主机键,请使用右 CTRL 键。
在 CentOS 中GUI 在 TTY 1CTRL + ALT + F1其他物理 TTY 是基于文本的。 在 Ubuntu 上GUI 在 TTY 7CTRL + ALT + F7其他物理 TTY 是基于文本的。
**注意:** 尝试在另一个 TTY 下加载 GUI 是不明智的,因为这可能耗用大量资源,但这是可能的。
当 Linux 启动时,不管是 CentOS 还是 Ubuntu默认的 TTY 都是打开的。如果安装了 GUI则对于 CentOS 为 TTY1对于 Ubuntu 为 TTY7。如果打开终端窗口伪TTY并使用命令 “who”你看到正在使用的 TTY 的列表。 如图 1 所示。
![Figure 01.jpg](https://www.linuxforum.com/attachments/figure-01-jpg.93/)
**图 1**
在图 1 中,你可以看到我当前登录到 TTY1非GUI。第二行连接显示我已登录到 GUITTY7以及两个伪 TTYPTS/1和 PTS/2。如图 2你可以看到新条目显示了远程伪 TTYPTS/3。 远程伪连接来自 IP 地址为 192.168.0.11 的系统。
![Figure 02.jpg](https://www.linuxforum.com/attachments/figure-02-jpg.94/)
**图 2**
可以使用诸如 “PuTTY” 或任何 SSH 的客户端(如果远程 Linux 系统上启用了 SSH之类的应用程序进行远程 TTY 连接。
如果终端窗口有小字体,你可以使用 CTRL + SHIFT 键和 “+” 键来放大字体。多次按下它使每次都更大。要缩小大小请使用CTRL + - 不断缩小。要使终端字体恢复为原始大小,请按下 CTRL + 0。
**注意:** 请注意,在组合键不再工作之前,字体将只能变大或变小,。
希望你现在已经了解各种类型的 TTY。让我们看看一些可以在 TTY 中使用的命令。
**命令**
其中一个命令前面已经讨论过了。命令 “who” 用于显示谁登录到了系统。
另一个命令是 “pwd”。命令 “pwd” 代表“打印工作目录”。该命令返回你所在的当前目录。例如,如果终端提示符是 “[jbuse@localhost〜]$”,则用户名为 “jbuse”当前目录为〜。波浪号指定用户的主文件夹。主文件夹应该是 “/home/_username_”。用户名是用于登录系统的名称。
要列出当前文件夹的内容,请使用命令 “ls”。“ls” 命令代表 List。如果未指定任何选项则列出当前文件夹。如果给出文件夹名称则会列出该文件夹的内容。例如要查看 “media” 文件夹的内容,你可以使用命令 “ls /media”。
在 “ls” 后面我们可以添加一些选项显示更多详细信息或特定详细信息。如果你想看到所有的文件夹和文件,即使是隐藏的,请使用选项 “-a”。要查看当前目录中的所有文件和文件夹请使用命令 “ls -a”。隐藏的文件和文件夹将在名称前面显示一个句点。
要在每个文件夹名称后看到正斜杠(/),请使用 “-F” 选项。当前文件夹列表将是 “ls -F”。
“-F” 用于按文件类型对文件进行分类。符号链接在文件夹名称后用“@”表示。
你可以把这两个选项连在一起形成 “ls -aF”。
**注意:** 一些选项可能有不同的情况。选项区分大小写。
另一个选项是显示长列表的 “-l”。示例输出如图 3 所示。文件夹和文件名称列在右侧。文件为白色,文件夹为深蓝色,符号链接为浅蓝色。如图 3 所示,符号链接 “vtrgb” 是来自 “/etc/alternatives/vtrgb” 的链接。
![Figure 03.jpg](https://www.linuxforum.com/attachments/figure-03-jpg.95/)
**图 3**
左侧的第一列是文件或文件夹的权限。第一个字母是 “d” 的为目录,是 “-” 的为文件。接下来的三个字母显示所有者的权限“r” - 读、“w” - 写、“x” - 执行),后面是组权限以及“其他”的权限。下一列数字显示指向文件或文件夹的链接数。下一列是所有者名称,后面是所有组名称。下一列是文件或文件夹在存储设备上占用的字节数。接下来的三列是文件上次修改的月份、日期和年份。最后一列是路径名。
目前为止,你可以看到列表按字母顺序排序。要颠倒从 “z” 到 “a” 而不是 “a” 到 “z” 的顺序,请使用 “-r” 选项。“-r” 或 reverse 选项使 ls 命​​令反转输出顺序。
要按修改的时间戳列出文件,请使用 “-t” 选项。顺序是从最近修改到最早的修改日期。当然,在命令 “ls -tr” 中,要颠倒顺序请同时使用 “-t” 和 “-r”。
如果你不喜欢看文件占用的长字节数,使用选项 “-h”。输出将会更易读如 “4.0K” 而不是 “4096”。
要获取单个文件夹的特定信息,请使用选项 “-d”但必须指定该文件夹。例如要查看文件夹 “/media” 的详细信息,请使用命令 “ls -ld /media”。
另一个要熟悉的命令是命令 “cat”。命令 “cat” 用于将标准输入(文件)复制到标准输出(屏幕)。使用 “cat” 可以轻松地查看文件的内容。例如,要查看名为 “text” 的文件的内容,请使用命令 “cat text”如果你与文件 “text” 在同一个文件夹中。如果你不在同一个文件夹中,那么你必须指定位置。例如,如果文件 “text” 在文件夹 “/home/jarret/test/” 中,那么命令将是
cat /home/jarret/test/text”。
另一个非常有用的命令是 “man”。“man” 命令用于查看特定命令的文档。例如,要查看命令 “ls” 的帮助页面,请使用命令 “man ls”。
**注意:** 记住,在 LFCS 考试中,你可以使用 “man” 命令。
查看这些命令并测试它们以熟悉它们。使用 “man” 命令,查看本文中的命令以查看其他可用的选项。
**注意:** 我对传递给命令来改变功能或输出的单词倾向于用 “options”。有些人可能会使用 “parameter”“argument” 等词。它们往往是可互换的。
--------------------------------------------------------------------------------
via: https://www.linuxforum.com/threads/lfcs-command-line-basics.3334/
作者:[Jarret][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linuxforum.com/members/jarret.268/