[Linux] Linux super full practical instruction Daquan

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_42322103/article/details/96307643

Operational level and retrieve the root password

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

Here Insert Picture Description
Commonly run level 3 and 5

To modify the default run level can change the file / etc / inittab the id: 5: initdefault: This line of digital commands:

 init[012356]

Retrieve the root password

Ideas: into single-user mode, and then modify the root password. Because the single-user mode, root can log in without a password.

Here Insert Picture Description
Here Insert Picture Description
Enter a e

1 space and then enter
Here Insert Picture Description
the enter key enter
Here Insert Picture Description
input b start to enter into the system with root privileges so you can modify your password

Help command

man to get help

当我们对某个指令不熟悉时,我们可以使用Linux提供的帮助指令来了解这个指令的使用方法。

.基本语法

man [命令或配置文件](功能描述:获得帮助信息)

例如查看Is命令的帮助信息

Here Insert Picture Description
Here Insert Picture Description
会有详细信息的展示

help指令

.基本语法

help 命令 (功能描述:获得shell内置命令的帮助信息)

比如:查看cd命令的帮助信息
Here Insert Picture Description

文件目录类

pwd 指令

基本语法

pwd (功能描述:显示当前工作目录的绝对路径)

Here Insert Picture Description

ls指令

.基本语法

ls [选项] [目录或是文件]

.常用选项
-a:显示当前目录所有的文件和目录,包括隐藏的。
-l:以列表的方式显示信息
Here Insert Picture Description

cd 指令

基本语法

cd [参数](功能描述:切换到指定目录)

常用参数
绝对路径和相对路径
cd ~或者cd 回到自己的家目录
cd… 回到当前目录的上一级目录

mkdir指令

mkdir指令用于创建目录(make directory)

基本语法

mkdir [选项] 要创建的目录

常用选项
-p:创建多级目录
Here Insert Picture Description
多级目录
Here Insert Picture Description

rmdir指令

rmdir指令可以用来删除空目录
·基本语法

rmdir[选项]要删除的空目录

Here Insert Picture Description
使用细节
rmdir 删除的是空目录,如果目录下有内容时无法删除的。
提示:如果需要删除非空目录,需要使用

rm -rf 要删除的目录

Here Insert Picture Description

touch指令

touch指令创建空文件
基本语法

touch文件名称

Here Insert Picture Description
一次性创建多个文件也是OK的
Here Insert Picture Description

cp指令

cp指令拷贝文件到指定目录

基本语法

cp [选项] source dest

常用选项
r:递归复制整个文件夹

将/home/dog/aaa/aaa.txt拷贝到/home/dog/bbb目录下
Here Insert Picture Description
Here Insert Picture Description

cp aaa.txt /home/dog/bbb

表示将当前目录的aaa.txt文件拷贝到指定这个目录下


递归复制整个文件夹
将dog目录的所有文件拷贝到新建立的 biubiu文件中
Here Insert Picture Description

注意一定要有 -r
Here Insert Picture Description
这样一来 dog文件下的文件就复制到了biubiu文件下了
即使不加/ 也会略过dog
Here Insert Picture Description

rm指令

rm指令移除文件或目录
·基本语法

rm [选项] 要删除的文件或目录

常用选项
-r:递归删除整个文件夹
f:强制删除不提示
.
将/home/dog/aaa/aaa.txt删除
Here Insert Picture Description

递归删除整个文件夹 /home/dog/bbb
Here Insert Picture Description
使用细节
强制删除不提示的方法:带上-f参数即可
Here Insert Picture Description

mv指令

mv 移动文件与目录 或 重命名
基本语法

mv  oldNameFile   newNameFile(功能描述:重命名)
mv  /temp/movefile  /targetFolder(功能描述:移动文件)

演示: 将/home/dog/aaa/aaa.txt文件重新命名为lala.txt
Here Insert Picture Description

将/home/dog/lala.txt文件移动到/home/dog/bbb目录下
Here Insert Picture Description

cat指令

cat查看文件内容 是以只读的方式打开

基本语法

cat [选项] 要查看的文件

常用选项
-n:显示行号

演示:/ect/profile文件内容,并显示行号
Here Insert Picture Description

·使用细节
cat只能浏览文件,而不能修改文件,为了浏览方便,一般会带上管道命令more
Here Insert Picture Description
按回车 就会出现下一行
按空格键就进入了下一页

more指令

more指令是一个基于vi编辑器的文本过滤器,它以全屏幕的方式按页显示文本文件的内容。
more指令中内置了若干快捷键,详见操作说明

基本语法

more 要查看的文件

·操作说明
Here Insert Picture Description

采用more查看文件/etc/profile
Here Insert Picture Description

less指令

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

基本语法

less 要查看的文件

操作说明
Here Insert Picture Description

>指令和>>指令

>输出重定向和>>追加

输出重定向会把原来的内容覆盖掉

.基本语法

ls-1>文件  (功能描述:列表的内容写入文件a.txt中(覆盖写))
Is-al>>文件   (功能描述:列表的内容追加到文件aa.txt的末尾)
cat 文件1>文件2  (功能描述:将文件1的内容覆盖到文件2)
echo"内容">>文件

Here Insert Picture Description
ls -l显示文件的列表 然后下面的ls -l > a.txt将列表的内容添加到a.txt中
没有a.txt文件就创建一个 有的话就直接覆盖写入了

这里追加写入一下
Here Insert Picture Description
下面演示 第三个命令
Here Insert Picture Description

第四个命令
Here Insert Picture Description

echo指令

echo输出内容到控制台。
基本语法

echo  [选项]  [输出内容]

使用echo指令输出环境变量
Here Insert Picture Description
使用echo指令输出hello,world!
Here Insert Picture Description

head指令

head用于显示文件的开头部分内容,默认情况下head指令显示文件的前10行内容

基本语法

head 文件(功能描述:查看文件头10行内容)
head-n 5 文件(功能描述:查看文件头5行内容,5可以是任意行数)

Here Insert Picture Description

tail指令

tail用于输出文件中尾部的内容,默认情况下tail指令显示文件的前10行内容。

基本语法

tail  文件(功能描述:查看文件头10行内容)
tail  -n  5  文件(功能描述:查看文件头5行内容,5可以是任意行数)
tail  -f  文件(功能描述:实时追踪该文档的所有更新)

第三条 是很重要的

查看/etc/profile最后5行
Here Insert Picture Description
实时监控bbb.txt,看看到文件有变化时,是否看到实时的追加日期
Here Insert Picture Description

ln指令

软链接也成为符号链接,类似于windows里的快捷方式,主要存放了链接其他文件的路径
这不是大写的i 而是大写是L的l

基本语法

In -s [原文件或目录] [软链接名] (功能描述:给原文件创建一个软链接)

在/home目录下创建一个软连接linkToRoot,连接到/root目录
Here Insert Picture Description
Here Insert Picture Description
cd到linkToRoot试试看哈
Here Insert Picture Description
这个是和连接的目录显示的是一样的


删除软连接linkToRoot
Here Insert Picture Description

细节说明
当我们使用pwd指令查看目录时,仍然看到的是软链接所在目录。

history指令

查看已经执行过历史命令,也可以执行历史指令
基本语法

history(功能描述:查看已经执行过历史命令)

显示所有的历史命令
Here Insert Picture Description
还有一大堆


显示最近使用过的5个指令。
Here Insert Picture Description

执行历史编号为156的指令
Here Insert Picture Description

时间日期类

date指令-显示当前日期

.基本语法

date(功能描述:显示当前时间)
date +%Y(功能描述:显示当前年份)
date +%m(功能描述:显示当前月份)
date +%d(功能描述:显示当前是哪一天)
date "+%Y-%m-%d %H:%M:%S"(功能描述:显示年月日时分秒)

Here Insert Picture Description
Here Insert Picture Description
基本语法

date-s字符串时间

时间设置的字符串 与上面显示的形式保持一致

cal指令

查看日历指令
基本语法

cal [选项] (功能描述:不加选项,显示本月日历)

Here Insert Picture Description

搜索查找类

find指令

find指令将从指定目录向下递归地遍历其各个子目录,将满足条件的文件或者目录显示在终端。
.基本语法

find [搜索范围] [选项]

.选项说明
Here Insert Picture Description

按文件名:根据名称查找/home目录下的a.txt文件
Here Insert Picture Description
第二个参树是搜索的范围 -name 按照文件名 最后一个是文件


按拥有者:查找/home目录下,用户名称为root的文件
Here Insert Picture Description


查找整个linux系统下大于200m的文件(+n大于 -n小于 n等于)
Here Insert Picture Description
查询/home 目录下所有以.txt结尾的文件
Here Insert Picture Description

locate指令

locaate指令可以快速定位文件路径
locate指令利用事先建立的系统中所有文件名称及路径的locate数据库实现快速定位给定的文件。
Locate指令无需遍历整个文件系统,查询速度较快。
为了保证查询结果的准确度,管理员必须定期更新locate时刻。

基本语法

locate 搜索文件

.特别说明
由于locate指令基于数据库进行查询,所以第一次运行前,必须使用updatedb指令创建locate数据库。

[linux]centos7及以上找不到locate命令及locate搜索不到存在的文件

Here Insert Picture Description

grep指令和管道符号 |

管道符号的l是小写的字母哈

grep过滤查找,管道符,“l”,表示将前一个命令的处理结果输出传递给后面的命令处理。

基本语法

grep [选项] 查找内容源文件

· Common options
Here Insert Picture Description
in bbb.txt file copy dfa
Here Insert Picture Description
CAT bbb.txt get the file contents and gave it to grep dfa behind the subsequent operations

Compression and decompression class

gzip / gunzip instruction

gzip to compress a file, gunzip for decompression

The basic syntax

gzip 文件  (功能描述:压缩文件,只能将文件压缩为*。gz文件)
gunzip 文件.gz  (功能描述:解压缩文件命令)

Here Insert Picture Description
Detailed instructions
when we use gzip to compress the file, will not retain the original file.
Here Insert Picture Description
If you want to write a few compress multiple files in a single compressed file name in

zip / unzip instruction

for compressed zip file, unzip a decompression, in this project package will be released in useful
• Basic syntax

zip [选项]  XXx.zip 将要压缩的内容(功能描述:压缩文件和目录的命令)
unzip [选项] XXX.zip(功能描述:解压缩文件)

Common options zip
-r: recursive compression, ie compression directory

unzip the common options
-d <directory>: After you specify the directory where the file is decompressed

Here Insert Picture Description
Here Insert Picture Description

tar command

tar command is packed instruction, after the last file is packaged .tar.gz file.
The basic syntax

tar [选项] XXX.tar.gz  打包的内容 (功能描述:打包目录,压缩后的文件格式.tar.gz)

· Option Description
Here Insert Picture Description
Here Insert Picture Description
-zvcf to command option
a.tar.gz for the file name of the package
files to be packaged followed

Here Insert Picture Description
* May be omitted

Decompression:
Here Insert Picture Description
unzip to a specific directory

Here Insert Picture Description
-C need
to specify extract to that directory, prior to exist in order to succeed, otherwise it will error.

Guess you like

Origin blog.csdn.net/qq_42322103/article/details/96307643