A Linux Command Line Primer
n5321 | 2024年8月30日 17:24
to know how to work in a terminal environment, both locally and remotely.
Although GUIs can be an intuitive way to use a computer for many users, they often do not provide us with the greatest power over our machines, and they may prevent us from having full administrative access on our computers, including installing, modifying, or deleting software or files. Additionally, as GUIs are largely visual, they are often not as accessible as they could be for all users.
In your interactive browser terminal, there should be a dollar sign, $
and a blinking cursor. This is where you will begin to type commands to tell the terminal what to do.
In many of these Unix (or *nix-based) operating systems, the symbols at the end of the prompt may be a $
symbol or a #
symbol, which mean the following:
关于登录账号的权限问题。
$
or dollar sign — you are logged in as a regular user#
or hashtag/pound symbol — you are logged in as a user with elevated privileges
For our purposes within the browser terminal below, you are logged in as a regular user, but you also have administrator privileges via the sudo
command.
好像是建议用普通账号登录,用sudu获取管理员权限。
Similarly, with a cloud server, it is possible to destroy a server and start fresh if something goes awry.
A command is an instruction that is given by a user, communicating what it is that the user wants the computer to do.
command 对计算机的操作本质上是类似一个军官对士兵的指挥。
The pwd
command stands for “present working directory,” and it lets you know where you are within the current filesystem. linux命令都是这种单词首字母的缩写!
This value (the name of the folder) is known as an argument, which is an input being given to the command. If you are familiar with natural language grammar, you can think of the argument as an object that is being acted upon by the verb of the command.
We’ll begin by using the touch
command, which can create a new file or modify an existing file.
We can use echo
directly on the command line to have the interface repeat after us. The traditional first program, "Hello, World!"
, can be written with echo
like so:
这个echo像是print
OutputHello, World!
we can use a command-line text editor. Several popular choices exist, including Vim and Emacs. For our purposes, we’ll use nano, which is a less complex CLI text editor program that we can use to begin our exploration.
三个编辑器
Vim Emacs and nano
With your file now containing the text you would like, we can now save and close the file. You may notice that there is some guidance at the bottom of your terminal window:
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell
第一次最烦的就是这个编辑器的存储、查看方式。
他本质上好像是不能用鼠标的。
Here, the ^
symbol refers to the Control
or CTRL
key on your keyboard, and the output above tells us that we need to combine that key with X
(use this lower case, without pressing the SHIFT
key) in order to leave the file. Let’s press those two keys together:
CTRL x
Autocompletion and History
Many versions of the command line, including the interactive terminal embedded in this tutorial, allow you to autocomplete and to reuse commands as you go. This supports you moving more quickly as it saves you typing time.