Linux practical instruction (1)

Specifies the run level

Run Level Description : 0: off
1: single-user to retrieve lost password] [
2: multi-user state no network service
3: multi-user states are network services
4: The system does not use the reserved user
5: graphical interface
to reboot the system: 6
common run level 3 and 5, to modify the default run level can be changed file / etc / inittab the id: 5: initdefault: the figures in this row
may be input instructions / ect / inittab view vim
Here Insert Picture Description
default level is 5
switch to the specified run level instruction
Here Insert Picture Description
into the level 3 re-enter login init5 can switch back to level 5Here Insert Picture Description

Help command

When we are not familiar with some instruction, we can use the help command to provide Linux to learn how to use this directive.
1, man get help

The basic syntax:
man [command or configuration file] (Function Description: get help)
Case: View help information ls command
Here Insert Picture Description
Here Insert Picture Description
here is space to turn down page by page, enter as the last line by line to turn down: Exit

2, help command
help command (Function Description: shell built-in commands to get help information)
Case: View help information cd command
Here Insert Picture Description

File Directory class

3、pwd 指令
基本语法 : pwd (功能描述:显示当前工作目录的绝对路径)
案例:显示当前工作目录的绝对路径
Here Insert Picture Description
4、ls 指令
基本语法 : ls [ 选 项] [目录或是文件]
常用选项:
-a :显示当前目录所有的文件和目录,包括隐藏的。
-l :以列表的方式显示信息
Here Insert Picture Description
Here Insert Picture Description

5、cd 指令
基本语法 : cd [参数] (功能描述:切换到指定目录)
常用参数:
绝对路径和相对路径
绝对路径:从根目录开始到达指定文件的路径
相对路径:从你当前所在位置到达指定文件的路径

cd ~或者cd返回自己的home目录
cd …返回上一级
Here Insert Picture Description
mkdir 指令
mkdir 指令用于创建目录(make directory)
语法 : mkdir [选项] 要创建的目录
常用选项:
-p :创建多级目录
Here Insert Picture Description

6、rmdir 指令
介绍 rmdir指令 删除空目录
基本语法
rmdir [选项] 要删除的空目录
Here Insert Picture Description

7、touch 指令
touch 指令创建空文件
基本语法 : touch 文件名称• 应用实例
Here Insert Picture Description
8、cp 指令
cp 指令拷贝文件到指定目录
基本语法 : cp [选项] source dest
常用选项:
-r :递归复制整个文件夹
案例 1: 将 /home/a.txt 拷贝到 /home/bbb 目录下[拷贝单个文件]
Here Insert Picture Description案例2:
将/home/test 整个目录拷贝到 /home/zwj 目录
Here Insert Picture Description

9、rm 指令
rm 指令移除【删除】文件或目录
基本语法rm:[选项] 要删除的文件或目录
常用选项:
-r :递归删除整个文件夹
-f : 强制删除不提示
案例:将 /home/a.txt 删除
Here Insert Picture Description

案例2:删除zwj下的test文件夹
Here Insert Picture Description

10、mv 指令
mv 移动文件与目录或重命名
基本语法:
mv oldNameFile newNameFile (功能描述:重命名)
mv /temp/movefile /targetFolder (功能描述:移动文件)
案例 1: 将 /home/a.txt 文件 重新命名为 pig.txt
Here Insert Picture Description
案例 2:将 /home/pig.txt 文件 移动到 /zwj目录下
Here Insert Picture Description

11、cat 指令
cat 查看文件内容,是以只读的方式打开。
基本语法cat [选项] 要查看的文件
常用选项
-n :显示行号
Here Insert Picture Description

使用细节cat 只能浏览文件,而不能修改文件,为了浏览方便,一般会带上 管道命令 | morecat 文件名 | more [分页浏览]Here Insert Picture Description
Here Insert Picture Description
这里按空格是一页一页的阅读 enter是一行一行的阅读

12、more 指令
more 指令是一个基于 VI 编辑器的文本过滤器,它以全屏幕的方式按页显示文本文件的内容。
more 指令中内置了若干快捷键
基本语法 : more 要查看的文件
Here Insert Picture Description
快捷键一栏
Here Insert Picture Description

13、less 指令
less 指令用来分屏查看文件内容,它的功能与 more 指令类似,但是比 more 指令更加强大,支持各种显示终端。less 指令在显示文件内容时,并不是一次将整个文件加载之后才显示,而是根据显示需要加载内容,对于显示大型文件具有较高的效率。
基本语法:less 要查看的文件

快捷键
Here Insert Picture Description

14、> 指令 和 >> 指令
介绍
一: >指 令 和 >> 指 令
1: >输出重定向 : 会将原来的文件的内容覆盖
2: >> 追加: 不会覆盖原来文件的内容,而是追加到文件的尾部。
基本语法:
ls -l >文件(功能描述:列表的内容写入文件 a.txt 中(覆盖)如果文件不存在就创建改文件)
Here Insert Picture Description

ls -al >>文件 (功能描述:列表的内容追加到文件 a.txt 的末尾)
Here Insert Picture Description
Here Insert Picture Description
15、echo 指令
echo 输出内容到控制台。
基本语法:echo [选项] [输出内容]
案例: 使用 echo 指令输出环境变量,输出当前的环境路径
Here Insert Picture Description

16、head 指令
head 用于显示文件的开头部分内容,默认情况下 head 指令显示文件的前 10 行内容
基本语法:
head 文件 (功能描述:查看文件头 10 行内容)
head -n 5 文件 (功能描述:查看文件头 5 行内容,5 可以是任意行数)
案例: 查看/etc/profile 的前面 5 行代码
Here Insert Picture Description

17、tail 指令
tail 用于输出文件中尾部的内容,默认情况下 tail 指令显示文件的后 10 行内容。基本语法:

  1. tail 文件 (功能描述:查看文件后 10 行内容)2
  2. tail -5文件 (功能描述:查看文件后 5 行内容,5 可以是任意行数)
  3. tail -f 文件 (功能描述:实时追踪该文档的所有更新,工作经常使用)

最后一个功能演示:
追踪x.txt文件

Here Insert Picture Description

向x.txt文件里追加内容
Here Insert Picture Description

实时更新
Here Insert Picture Description

18、ln指令
软链接也叫符号链接,类似于 windows 里的快捷方式,主要存放了链接其他文件的路径
基本语法 : ln -s [原文件或目录] [软链接名] (功能描述:给原文件创建一个软链接)
Here Insert Picture Description
当我们使用 pwd 指令查看目录时,仍然看到的是软链接所在目录。

19, history command
to view the history command has been executed, execution history can also command
the basic syntax: history (Function Description: View the history command has been executed)
Here Insert Picture Description
Show 10 most recently used instructions
Here Insert Picture Description

Published 45 original articles · won praise 43 · views 7087

Guess you like

Origin blog.csdn.net/qq_42193790/article/details/104327168