2019-2020-1学期 20192428《THE LINUX COMMAND LINE 》读数笔记一

2019-2020-1学期 20192428《THE LINUX COMMAND LINE 》读数笔记一

首先请看我对第1、2、3小节的脑图


① WHAT IS THE SHELL?

Bash,Unix shell的一种,在1987年由布莱恩·福克斯为了GNU计划而编写。1989年发布第一个正式版本,原先是计划用在GNU操作系统上,但能运行于大多数类Unix系统的操作系统之上,包括Linux与Mac OS X v10.4都将它作为默认shell。

当我们谈到命令行时,实际上指的是shellshell是一个接收键盘命令并将其传递给操作系统执行的程序。
“When we speak of the command line, we are really referring to the shell. The shell is a program that takes keyboard commands and passes them to the operating system to carry out.”

Terminal Emulators ——终端仿真器

“A number of other terminal emulators are available for Linux, but they all do basically the same thing: give us access to the shell.”

Keystrokes ——认识你的输入

通常来讲,Linux的输入处往往是这样的: [me@linuxbox ~]$
这里@为一个分界:之前为用户名(username),之后为机器名(machinename),同时$表示用户权限为普通,有时$会变为#,#代表权限为超级用户特权。当你的shell中出现这个东西,表示系统以及做好准备进行输入了。

Command History 以及 Cursor Movement

从keyboard操作上来看,将这两标题可以合并为一个内容,即为上下左右键(↑、↓、←、→)对应的快捷操作。其中:
上(↑):回溯指令,追查上一条指令并将其打进你的输入框,默认最多可追溯500条记录。
下(↓):跳到目前指令记录的下一条指令。
左(←)右(→):光标移动。

*If we press the up-arrow key, we see that the previous command kaekfjaeifj reappears after the prompt. This is called command history. Most Linux distributions remember the last 500 commands by default. Press the down-arrow key, and the previous command disappears.

*Recall the previous command with the up-arrow key again. Now try the left- and right-arrow keys. See how we can position the cursor anywhere on the command line? This makes editing commands easy.

Try Some Simple Commands

书中举例了一些简单的Linux操作:

指令 功能
[me@linuxbox ~]$ date 显示当前日期
[me@linuxbox ~]$ cal 显示日历(本月)
[me@linuxbox ~]$ df 当前磁盘驱动器上的空闲空间量
[me@linuxbox ~]$ free 显示空闲内存的数量
[me@linuxbox ~]$ exit 结束终端对话

Understanding the Filesystem Tree

首先看一张我截取自己计算机文件夹的截图:

上图为计算机字体库所在文件位置,可见位置为:
此电脑 → C盘 → Windows文件夹 → Fonts文件夹
而这种目录结构正被称为:分层目录结构
书中原文是这样写的:

Like Windows, a Unix-like operating system such as Linux organizes its files in what is called a hierarchical directory structure. This means that they are organized in a tree-like pattern of directories (sometimes called folders in other systems), which may contain files and other directories. The first directory in the filesystem is called the root directory. The root directory contains files and subdirectories, which contain more files and subdirectories, and so on.

正是存在这种结构使得计算机文件整齐有序,而Linux不同于Windows系统的一点是,整个系统由一颗树(The Filesystem Tree)构成,存储设备根据系统管理员、负责系统维护的人员的意愿被附加(或者更正确地说是安装)在树的不同位置。

The Current Working Directory、Listing the Contents of a Directory 、Changing the Current Working Directory

这三小节内容可以整理在一起是因为,三节内容共同讲述了如何“自由的在Linux系统中行走”,如何在shell中利用指令,达到穿梭在各个文件夹以及文件中。而三条指令分别是:pwd(查看当前文件位置)ls(查看文件夹中所有文件及子文件夹)cd(进入、退出文件夹)

pwd指令:

输入:[me@linuxbox ~]$ pwd
输出:/home/me

ls指令

输入:[me@linuxbox ~]$ ls
输出:Desktop Documents Music Pictures Public Templates Videos

cd指令

输入:[me@linuxbox ~]$ cd /usr/bin
验证:[me@linuxbox bin]$ pwd
输出:/usr/bin

IMPORTANT FACTS ABOUT FILENAMES

这里我将它单独分出一个小节,作为之前总结内容的补充。
该部分讲了关于前面内容的补充或一些细节的问题。

  • 在Linux系统下,部分文件名是被隐藏的(文件夹名以.为起始),因此使用ls往往无法发现隐藏的文件,可以使用 ls -a指令 勘察所有文件(包括隐藏文件)
  • Filenames and commands in Linux, as in Unix, are case sensitive. The filenames File1 and file1 refer to different files. 即文件名分大小写。
  • Linux系统中文件名不会规定文件类型,举个例子,Windows中filename.txt代表文件为一个txt文本类型文件,但在Linux中不使用这种方式区分文件类型,而是在文件中有专门方法规定文件的所属类型。
  • *Though Linux supports long filenames that may contain embedded spaces and punctuation characters, limit the punctuation characters in the names of files you create to period, dash (hyphen), and underscore. Most importantly, do not embed spaces in filenames. Embedding spaces in filenames will make many command line tasks more difficult, as we will discover in Chapter 7. If you want to represent spaces between words in a filename, use underscore characters. You will thank yourself later. * 关于文件命名问题,在后面的章节也会再进行叙述。

③EXPLORING THE SYSTEM

第三块内容集中讲了关于Linux系统的三个指令:ls、file、less,下面让我们一起来看看它们的用法吧。

More Fun with ls

在讲ls指令之前,我们需要明确,在Linux系统中指令的规则,即选项与参数:

Options and Arguments

命令往往伴随着选项和参数而执行,选项代表命令执行时的举止(behavior),而参数则代表了命令执行的目标/范围/方式等。
因此大多数指令的完整形式为:**command -options arguments **
举个栗子: [me@linuxbox ~]$ ls -lt这条指令中,ls表示查看当前文件夹中文件,而-lt中,l选项产生长格式输出,t选项根据文件修改时间排序。
在脑图中也有对这个知识点的详细总结,在此就不多加赘述。
接下来看看ls指令的options选项表格:

posted @ 2019-12-26 22:34  岁岁敲代码  阅读(224)  评论(0编辑  收藏  举报