Linux 终端:终极速查表
TL;DR
基本命令
更改目录命令(cd)
列表命令(ls)
搜索
历史
使用文件和目录
最后的话
如果你是 Linux 用户,终端可能是你拥有过的最强大的工具。但问题是,如果你想从终端中获益,你需要学习如何使用它。
过去几个月,我一直在使用终端,并整理出了一份我经常使用的实用命令清单。如果我遗漏了一些重要的命令,请告诉我,以便我将其添加到以后的帖子中。
💡 如果您发现此内容有价值,您可以在Twitter和Instagram上关注我。
TL;DR
- 基本命令
- 放大 ➜
[CTRL] + [+]
- 缩小 ➜
[CTRL] + [-]
- 打印工作目录 ➜
pwd
- 清除终端 ➜
[CTRL] + [l]
或clear
- 分配别名 ➜
alias [alias-name]="[command-to-run]"
- 获取文件 ➜
source [name-of-the-file-to-read-and-execute]
- 放大 ➜
- 更改目录命令(cd)
- 移动到特定目录➜
cd [name-of-your-directory]
- 移至父目录➜
cd ..
- 移动到主目录➜
cd
或cd ~
- 移动到你上次所在的目录➜
cd -
- 移动到特定目录➜
- 列表命令(ls)
- 列出所有可见文件和目录➜
ls
- 列出所有文件和目录(包括隐藏文件)➜
ls -a
- 入围格式 ➜
ls -l
- 人类可读格式➜
ls -lh
- 组合参数:人类可读格式 + 隐藏文件 ➜
ls -lah
- 了解有关 ls 命令的更多信息➜
man ls
- 列出所有可见文件和目录➜
- 搜索
- 找到程序的二进制文件➜
which [name-of-the-program]
- 找到程序的二进制文件、源代码和用户手册➜
whereis [name-of-the-program]
- 按名称查找文件和目录➜
find [path-to-search] -iname [name-of-the-file-you-want-to-search]
- 了解有关 find 命令的更多信息 ➜
man find
- 了解有关 find 命令的更多信息 ➜
- 获取命令的简要描述 ➜
whatis [command-name]
- 找到程序的二进制文件➜
- 历史
- 获取之前的命令(逐个)➜ 使用
Up Arrow key
⬆️浏览历史记录 - 获取以前的命令(完整列表)➜
history
。 - 重复历史记录中的命令(bang 命令)
history
➜➜![number-of-the-command-to-repeat]
- 重复上一个命令(bang-bang 命令)➜
!!
- 获取之前的命令(逐个)➜ 使用
- 使用文件和目录
- 创建一个新文件(不打开)➜
touch [name-of-your-file]
- 使用文本编辑器创建新文件 ➜
vim [name-of-your-file]
或nano [name-of-your-file]
- 复制文件➜
cp [source-path-of-your-file] [destination-path-for-your-file]
- 创建新目录➜
mkdir [new-directory-name]
- 删除一个空目录➜
rmdir [name-of-the-directory-you-want-to-remove]
- 删除命令(rm)
- 删除文件 ➜
rm [name-of-your-file]
- 递归删除目录(谨慎使用)➜
rm -rf [name-of-your-directory]
- 删除文件 ➜
- 连接命令(cat)
- 查看单个文件 ➜
cat [name-of-your-file]
- 查看单个文件(包括行号)➜
cat -n [name-of-your-file]
- 将一个文件的内容复制到另一个文件➜
cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
- 了解有关 cat 命令的更多信息➜
man cat
- 查看单个文件 ➜
- 移动命令 (mv)
- 移动文件 ➜
mv [source-path-of-your-file] [destination-path-for-your-file]
- 重命名文件➜
mv [name-of-your-file] [new name-of-your-file]
- 移动文件 ➜
- 创建一个新文件(不打开)➜
基本命令
放大
类型[CTRL] + [+]
缩小
类型[CTRL] + [-]
pwd:打印工作目录命令
它从根目录开始打印工作目录路径。
mauro_codes@DESKTOP-HIQ7662:~$ pwd
/home/mauro_codes
mauro_codes@DESKTOP-HIQ7662:~/projects$ pwd
/home/mauro_codes/projects
清除命令
键入clear
或[CTRL] + [l]
清除整个终端屏幕并获得干净的终端以继续工作。
别名命令
如果您经常运行某个较长的命令,并且希望节省时间,则可以为该命令指定一个较短的别名。键入以下alias [alias-name]="[command-to-run]"
命令即可指定新别名:
## Running the ls command
mauro_codes@DESKTOP-HIQ7662:~$ ls
projects
## Assign an alias, so we don't need to add the arguments every time we need to list something
mauro_codes@DESKTOP-HIQ7662:~$ alias ls="ls -lah"
## Running ls again (we get the result of `ls -lah`)
mauro_codes@DESKTOP-HIQ7662:~$ ls
total 16K
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 17:41 .
drwxr-xr-x 1 root root 512 Jan 22 10:38 ..
-rw------- 1 mauro_codes mauro_codes 3.0K Jan 22 23:58 .bash_history
-rw-r--r-- 1 mauro_codes mauro_codes 220 Jan 22 10:38 .bash_logout
-rw-r--r-- 1 mauro_codes mauro_codes 3.7K Jan 22 17:32 .bashrc
-rw-r--r-- 1 mauro_codes mauro_codes 807 Jan 22 10:38 .profile
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 projects
请注意,此别名不会被保留以供将来使用。如果您想保留别名,请将其添加到主目录中 .bashrc 文件的末尾。
获取文件
您可以使用该source
命令逐行读取并执行文件的内容。输入source [name-of-the-file-to-read-and-execute]
:
## Print the content of the script.txt file (contains two commands)
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cat script.txt
echo "hello world" ## Print a hello message
cal ## Print a calendar
## Source the script.txt to run each command inside
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ source script.txt
hello world
January 2021
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
更改目录命令(cd)
移动到特定目录
类型cd [name-of-your-directory]
:
## Check current directory
mauro_codes@DESKTOP-HIQ7662:~$ pwd
/home/mauro_codes
## Change directory
mauro_codes@DESKTOP-HIQ7662:~$ cd projects/
## Check new working directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ pwd
/home/mauro_codes/projects
移动到父目录
类型cd ..
:
## Check current directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ pwd
/home/mauro_codes/projects
## Move to the parent directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ cd ..
## Check new working directory
mauro_codes@DESKTOP-HIQ7662:~$ pwd
/home/mauro_codes
移动到主目录
键入cd ~
或仅cd
作为替代
## Check current directory
mauro_codes@DESKTOP-HIQ7662:~/projects/awesome-app$ pwd
/home/mauro_codes/projects/awesome-app
## Move to the home directory
mauro_codes@DESKTOP-HIQ7662:~/projects/awesome-app$ cd ~
## Check new working directory
mauro_codes@DESKTOP-HIQ7662:~$ pwd
/home/mauro_codes
移动到你上次所在的目录
输入cd -
以导航到您所在的上一个目录
## Check the current directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ pwd
/home/mauro_codes/projects/landing-page
## Move to another directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cd /home/mauro_codes/
## Check the new directory
mauro_codes@DESKTOP-HIQ7662:~$ pwd
/home/mauro_codes
## Go back to the previus directory you were in
mauro_codes@DESKTOP-HIQ7662:~$ cd -
/home/mauro_codes/projects/landing-page
列表命令(ls)
列出您当前所在目录的内容。
列出所有可见的文件和目录
输入ls
不带任何附加参数的命令即可获取所有文件和目录(此命令将排除诸如点文件之类的隐藏文件)。
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ pwd
/home/mauro_codes/projects
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ ls
awesome-app landing-page nextjs-tailwindcss-blog-starter personal-blog
列出所有文件和目录
键入ls -a
以获取所有文件和目录(包括隐藏文件)
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ pwd
/home/mauro_codes/projects
## List the content for the working directory (including hidden files)
mauro_codes@DESKTOP-HIQ7662:~/projects$ ls -a
. .. .config .configu awesome-app landing-page nextjs-tailwindcss-blog-starter personal-blog
长名单格式
键入ls -l
以获取所有可见文件和目录,包括权限、所有者、大小和修改日期和时间等其他元数据。
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/nextjs-tailwindcss-blog-starter$ pwd
/home/mauro_codes/projects/nextjs-tailwindcss-blog-starter
## List the content for the working directory (using the long listed format)
mauro_codes@DESKTOP-HIQ7662:~/projects/nextjs-tailwindcss-blog-starter$ ls -l
total 140
-rw-r--r-- 1 mauro_codes mauro_codes 4487 Jan 22 12:55 README.md
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 components
-rw-r--r-- 1 mauro_codes mauro_codes 1068 Jan 22 12:55 config.ts
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 helpers
人类可读格式
键入ls -lh
以获取长列表格式的所有可见文件和目录,但具有人类可读格式(用户友好的文件大小)。
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/nextjs-tailwindcss-blog-starter$ pwd
/home/mauro_codes/projects/nextjs-tailwindcss-blog-starter
## List the content for the working directory (using the long listed format + human readable format)
mauro_codes@DESKTOP-HIQ7662:~/projects/nextjs-tailwindcss-blog-starter$ ls -lh
total 140K
-rw-r--r-- 1 mauro_codes mauro_codes 4.4K Jan 22 12:55 README.md
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 components
-rw-r--r-- 1 mauro_codes mauro_codes 1.1K Jan 22 12:55 config.ts
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 helpers
合并参数
键入ls -lah
以获取人类可读格式的所有文件和目录(包括隐藏文件)。
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/nextjs-tailwindcss-blog-starter$ pwd
/home/mauro_codes/projects/nextjs-tailwindcss-blog-starter
## List the content for the working directory (include hidden files + human readable format)
mauro_codes@DESKTOP-HIQ7662:~/projects/nextjs-tailwindcss-blog-starter$ ls -lah
total 140K
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 13:08 .
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 ..
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 .git
-rw-r--r-- 1 mauro_codes mauro_codes 362 Jan 22 12:55 .gitignore
-rw-r--r-- 1 mauro_codes mauro_codes 4.4K Jan 22 12:55 README.md
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 components
-rw-r--r-- 1 mauro_codes mauro_codes 1.1K Jan 22 12:55 config.ts
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 22 12:55 helpers
了解有关ls
命令的更多信息
该命令有几十个参数可供使用ls
。如果你想使用 dig dipper,请在终端中
输入man ls
以显示该命令的用户手册ls
。
搜索
找到程序的二进制文件
如果你想找到特定命令或程序的二进制文件(可执行文件)的位置,你可以使用以下which
命令:
## Locate binary for the ls command
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ which ls
/usr/bin/ls
## Locate binary for git
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ which git
/usr/bin/git
找到程序的二进制文件、源代码和用户手册
您可以使用该whereis
命令查找程序的二进制文件、源代码和用户手册。您可以使用-b
、-m
和-s
参数分别将结果限制为二进制文件、手册和源代码。
## Locate binary, manual, and source for git
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ whereis git
git: /usr/bin/git /mnt/c/Program Files/Git/cmd/git.exe /usr/share/man/man1/git.1.gz
## Locate only binary and manual for Git, and only the manual for ls command
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ whereis -bm git -m ls
git: /usr/bin/git /mnt/c/Program Files/Git/cmd/git.exe /usr/share/man/man1/git.1.gz
ls: /usr/share/man/man1/ls.1.gz
按名称查找文件和目录
键入find [path-to-search] -iname [name-of-the-file-you-want-to-search]
以查找标题中包含给定名称的任何文件或目录。
- 搜索路径是可选的。如果未指定,该
find
命令将在当前工作目录(及其子目录)上运行。 - 该
-iname
参数意味着我们的搜索将不区分大小写。
- If you want to learn more about this command, type `man find` to display the user manual.
## Check current working directory
mauro_codes@DESKTOP-HIQ7662:~/projects$ pwd
/home/mauro_codes/projects
## Find files that contain "posts" on my current working directory and its descendants
mauro_codes@DESKTOP-HIQ7662:~/projects$ find -iname posts
./nextjs-tailwindcss-blog-starter/pages/posts
./nextjs-tailwindcss-blog-starter/posts
## Find files that contain "posts" on a specific directory and its descendants
mauro_codes@DESKTOP-HIQ7662:~/projects$ find ./nextjs-tailwindcss-blog-starter/pages/ -iname posts
./nextjs-tailwindcss-blog-starter/pages/posts
获取命令的简要描述
如果您不知道某个命令的作用,请输入whatis [command-name]
如下内容:
## Asking about the cat command
mauro_codes@DESKTOP-HIQ7662:~/projects$ whatis cat
cat (1) - concatenate files and print on the standard output
## Asking about the find command
mauro_codes@DESKTOP-HIQ7662:~/projects$ whatis find
find (1) - search for files in a directory hierarchy
历史
获取之前的命令(逐个获取)
你可以通过按 ⬆️ 来访问最近的命令Up Arrow key
。如果你想重复上一个命令,这非常有用。假设我们移动到一个特定的目录,然后像这样检查我们的工作目录:
## Move to a specific directory
mauro_codes@DESKTOP-HIQ7662:~$ cd projects/awesome-app/
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/awesome-app$ pwd
/home/mauro_codes/projects/awesome-app
⬆️ 我们将收到pwd
命令
⬆️⬆️ 我们将收到cd projects/awesome-app
命令
重复上一个命令(完整列表)
输入history
以获取包含您之前运行的命令的数字列表。然后,输入![number-of-the-command-to-repeat]
以重复该命令
## Get the history list
mauro_codes@DESKTOP-HIQ7662:~$ history
1 ls
2 clear
3 pwd
4 mkdir projects
5 cd projects
## Run command number 1 (ls)
mauro_codes@DESKTOP-HIQ7662:~$ !1
projects
重复上一个命令
输入!!
(bang-bang command) 重复上一个命令。当你忘记添加sudo
上一个命令时,这个命令尤其有用:
## Running update without sudo (Permission denied)
mauro_codes@DESKTOP-HIQ7662:~$ apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
## Using the bang-bang command to append the last command after sudo
mauro_codes@DESKTOP-HIQ7662:~$ sudo !!
sudo apt update
[sudo] password for mauro_codes:
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
...
使用文件和目录
创建一个新文件(不打开它)
键入touch [name-of-your-file]
创建一个新文件,而无需在文本编辑器中打开它。如果你只想创建一个空文件,但暂时不需要更改它,这个功能就很有用。
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ pwd
/home/mauro_codes/projects/landing-page
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md
## Create an empty js file
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ touch main.js
## List the content for the working directory (including your new file)
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md main.js
使用文本编辑器创建新文件
键入nano [name-of-your-file]
创建一个新文件,并使用文本编辑器nano打开它。如果你想了解更多关于 nano 的信息,你可以man nano
在终端上键入 来显示 nano 用户手册。
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ pwd
/home/mauro_codes/projects/landing-page
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md main.js
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ nano index.html
复制文件
您可以使用cp
(复制)命令复制文件和目录,
键入cp [source-path-of-your-file] [destination-path-for-your-file]
以将文件复制到新目标。
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index.html main.js temp
## Copy the README.md file into the temp directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cp README.md temp/README.md
## List the content for the working directory and check that your file is still there.
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index.html main.js temp
## List the temp directory's content and check if your file was copied.
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls temp/
README.md index-copy.html
创建新目录
键入mkdir [new-directory-name]
以在当前工作目录中创建新目录
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index-empty-copy.html index.html main.js
## Create a new directory called "scripts"
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ mkdir scripts
## List the content to check if our new directory was created
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index-empty-copy.html index.html main.js scripts
删除空目录
键入rmdir [name-of-the-directory-you-want-to-remove]
以删除空目录。请注意,此命令仅适用于空目录。
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index.html main.js temp
## Remove the "temp" empty directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ rmdir temp
## List the content and check that the directory was removed
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index.html main.js
删除命令(rm)
删除文件
键入rm [name-of-your-file]
以删除文件
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page/temp$ ls
README.md index-copy.html
## Remove the index-copy.html file
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page/temp$ rm index-copy.html
## List the content for the working directory and check that the file was removed
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page/temp$ ls
README.md
递归删除目录
键入rm -rfi [name-of-your-directory]
以递归方式删除目录及其所有文件和子目录。
请小心!这是您可以运行的最危险的命令之一。如果您运行
rm -rfi /
,您将删除整个根分区。请务必指定要删除的目录的路径。在此示例中,我添加了一个-i
参数来请求确认。
## List the content of the temp folder (It has one file)
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls temp/
total 0
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 24 19:45 .
drwxr-xr-x 1 mauro_codes mauro_codes 512 Jan 24 19:44 ..
-rw-r--r-- 1 mauro_codes mauro_codes 8 Jan 24 19:45 file.txt
## Recursively remove the temp folder
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ rm -rf temp/
## Check that the temp folder was removed
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls temp/
ls: cannot access 'temp/': No such file or directory
连接命令(cat)
您可以使用cat
(连接)命令从文件中读取数据并将其内容打印为输出
查看单个文件
类型cat [name-of-your-file]
:
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ pwd
/home/mauro_codes/projects/landing-page
## Print the content of the index.html file
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cat index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My Website</title>
</head>
<body>
<script src="js/main.js"></script>
</body>
</html>
查看单个文件,包括行号
类型cat -n [name-of-your-file]
:
## Check the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ pwd
/home/mauro_codes/projects/landing-page
## Print the content of the index.html file
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cat -n index.html
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <meta http-equiv="x-ua-compatible" content="ie=edge" />
6 <meta name="viewport" content="width=device-width, initial-scale=1" />
7
8 <title>My Website</title>
9 </head>
10
11 <body>
12 <script src="js/main.js"></script>
13 </body>
14 </html>
将一个文件的内容复制到另一个文件
类型cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
:
## Create an empty file called index-empty-copy.html
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ touch index-empty-copy.html
## Copy the content of index.html to index-empty-copy.html
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cat index.html > index-empty-copy.html
## Print the content of the index-empty-copy.html file
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ cat index-empty-copy.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>My Website</title>
</head>
<body>
<script src="js/main.js"></script>
</body>
</html>
了解有关cat
命令的更多信息
键入以显示命令man cat
的用户手册cat
移动命令 (mv)
您可以使用mv
(移动)命令移动和重命名文件
移动文件
键入mv [source-path-of-your-file] [destination-path-for-your-file]
以将文件移动到新目录
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index-empty-copy.html index.html main.js temp
## Move the index-empty-copy.html file to the temp directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ mv index-empty-copy.html temp/index-empty-copy.html
## List the content again and check that the file is no longer in the current working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls
README.md index.html main.js temp
## List the temp folder and check that the file is now there.
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page$ ls temp/
index-empty-copy.html
重命名文件
键入mv [name-of-your-file] [new name-of-your-file]
以重命名文件
## List the content for the working directory
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page/temp$ ls
index-empty-copy.html
## Rename the index-empty-copy.html file
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page/temp$ mv index-empty-copy.html index-copy.html
## List the content for the working directory (check if your file's name was updated)
mauro_codes@DESKTOP-HIQ7662:~/projects/landing-page/temp$ ls
index-copy.html
最后的话
我错过了这篇文章里很多强大的命令,但我决定把它们留到以后的文章里。这已经够长了。😄