<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>System File Security (系统文件安全) &#8211; Eternal Center</title>
	<atom:link href="https://eternalcenter-2021-12.github.io/category/system/system-network-system-security-system-log/system-security/system-file-security/feed/" rel="self" type="application/rss+xml" />
	<link>https://eternalcenter-2021-12.github.io/</link>
	<description></description>
	<lastBuildDate>Sun, 26 Dec 2021 09:07:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>[步骤] Linux 加密压缩 （tar 版）</title>
		<link>https://eternalcenter-2021-12.github.io/encryption-compression-tar/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 15 Nov 2021 15:52:52 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=18392</guid>

					<description><![CDATA[步骤一：创建测试文件 （补充：这里以创建 test.txt 文件为例） 步骤二：加密压缩文件或目录2.1 交互式加密压缩文件或目录 （补充：1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz （压缩）包为例2) 如果要以 bzip2 的格式进行压缩，则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz23) 如果要以 xz 的格式进行压缩，则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz） 2.2 非交互式加密压缩文件或目录 （补充：1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz （压缩）包并且将密码设置为 eternalcenter 为例2) 如果要以 bzip2 的格式进行压缩，则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test2.tar.bz23) 如果要以 xz 的格式进行压缩，则将命令中的 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/encryption-compression-tar/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] Linux 加密压缩 （tar 版）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h4>步骤一：创建测试文件</h4>



<pre class="wp-block-code"><code># touch test.txt</code></pre>



<p>（补充：这里以创建 test.txt 文件为例）</p>



<h4>步骤二：加密压缩文件或目录<br>2.1 交互式加密压缩文件或目录</h4>



<pre class="wp-block-code"><code># tar -zcf - test.txt | openssl des3 -salt | dd of=test1.tar.gz
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.
0+1 records in
0+1 records out
224 bytes copied, 7.04902 s, 0.0 kB/s</code></pre>



<p>（<br>补充：<br>1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz （压缩）包为例<br>2) 如果要以 bzip2 的格式进行压缩，则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2<br>3) 如果要以 xz 的格式进行压缩，则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz<br>）</p>



<h4>2.2 非交互式加密压缩文件或目录</h4>



<pre class="wp-block-code"><code># tar -zcf - test.txt | openssl des3 -salt -f eternalcenter | dd of=test2.tar.gz
des3: Unrecognized flag f
des3: Use -help for summary.
0+0 records in
0+0 records out
0 bytes copied, 0.00376576 s, 0.0 kB/s</code></pre>



<p>（<br>补充：<br>1) 这里以将 test.txt 文件加密压缩成 test1.tar.gz （压缩）包并且将密码设置为 eternalcenter 为例<br>2) 如果要以 bzip2 的格式进行压缩，则将命令中的 -zcf 换成 -jcvf 将 test1.tar.gz 换成 test2.tar.bz2<br>3) 如果要以 xz 的格式进行压缩，则将命令中的 -zcf 换成 -Jcvf 将 test1.tar.gz 换成 test2.tar.xz<br>）</p>



<h4>步骤三：解压加密文件或目录<br>3.1 交互式解压加密文件或目录<br>3.1.1 删除原测试目录和里面的文件</h4>



<pre class="wp-block-code"><code># rm -rf test.txt</code></pre>



<p>（补充：这里以删除 test.txt 文件为例）</p>



<h4>3.1.2 交互式解压加密文件或目录</h4>



<pre class="wp-block-code"><code># dd if=test2.tar.gz | openssl des3 -d | tar zxf -
0+1 records in
0+1 records out
224 bytes copied, 0.000589721 s, 380 kB/s
enter des-ede3-cbc decryption password:
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.</code></pre>



<p>（<br>补充：<br>1) 这里以解压 test2.tar.gz （压缩）包为例<br>2) 如果是 bzip2 格式的（压缩）包，则将命令中的 -zxf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2<br>3) 如果是 xz 格式的（压缩）包，则将命令中的 -zxf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz<br>）</p>



<h4>3.2 非交互式解压加密文件或目录<br>3.2.1 删除原测试目录和里面的文件</h4>



<pre class="wp-block-code"><code># rm -rf test.txt</code></pre>



<p>（补充：这里以删除 test.txt 文件为例）</p>



<h4>3.2.2 非交互式解压加密文件或目录</h4>



<pre class="wp-block-code"><code># dd if=test1.tar.gz | openssl des3 -d -k eternalcenter | tar zxf -
0+1 records in
0+1 records out
224 bytes copied, 0.000574539 s, 390 kB/s
*** WARNING : deprecated key derivation used.
Using -iter or -pbkdf2 would be better.</code></pre>



<p>（<br>补充：<br>1) 这里以解压 test1.tar.gz （压缩）包并且解压密码为 eternalcenter 为例<br>2) 如果是 bzip2 格式的（压缩）包，则将命令中的 -zxf 换成 -jcvf 将 test1.tar.gz 换成 test1.tar.bz2<br>3) 如果是 xz 格式的（压缩）包，则将命令中的 -zxf 换成 -Jcvf 将 test1.tar.gz 换成 test1.tar.xz<br>）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux 加密压缩 （zip 版）</title>
		<link>https://eternalcenter-2021-12.github.io/encryption-compression-zip/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 15 Nov 2021 15:48:09 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=18388</guid>

					<description><![CDATA[步骤一：创建测试目录和测试文件 （补充：这里以创建 test 目录和里面的 test.txt 文件为例） 步骤二：加密压缩文件或目录2.1 交互式加密压缩文件或目录 （补充：这里以将 test 目录和里面的 test.txt 文件加密压缩成 test1.zip （压缩）包为例） 2.2 非交互式加密解压文件或目录 （补充：这里以将 test 目录和里面的 test.txt 文件加密压缩成 test2.zip （压缩）包并且将密码设置为 eternalcenter 为例） 步骤三：解压加密文件或目录3.1 交互式解压加密文件或目录3.1.1 删除原测试目录和里面的文件 （补充：这里以删除 test 目录和里面的文件为例） 3.1.2 交互式解压加密文件或目录 （补充：这里以解压 test2.zip （压缩）包为例） 3.2 非交互式解压加密文件或目录3.2.1 删除原测试目录和里面的文件 （补充：这里以删除 test 目录和里面的文件为例） 3.2.2 非交互式解压加密文件 （补充：这里以解压 test2.zip （压缩）包并且解压密码为 eternalcenter 为例）]]></description>
										<content:encoded><![CDATA[
<h4>步骤一：创建测试目录和测试文件</h4>



<pre class="wp-block-code"><code># mkdir test
# touch test/test.txt</code></pre>



<p>（补充：这里以创建 test 目录和里面的 test.txt 文件为例）</p>



<h4>步骤二：加密压缩文件或目录<br>2.1 交互式加密压缩文件或目录</h4>



<pre class="wp-block-code"><code># zip -re test1.zip test
Enter password: 
Verify password: 
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)</code></pre>



<p>（补充：这里以将 test 目录和里面的 test.txt 文件加密压缩成 test1.zip （压缩）包为例）</p>



<h4>2.2 非交互式加密解压文件或目录</h4>



<pre class="wp-block-code"><code># zip -rP eternalcenter test2.zip test
  adding: test/ (stored 0%)
  adding: test/test.txt (stored 0%)</code></pre>



<p>（补充：这里以将 test 目录和里面的 test.txt 文件加密压缩成 test2.zip （压缩）包并且将密码设置为 eternalcenter 为例）</p>



<h4>步骤三：解压加密文件或目录<br>3.1 交互式解压加密文件或目录<br>3.1.1 删除原测试目录和里面的文件</h4>



<pre class="wp-block-code"><code># rm -rf test</code></pre>



<p>（补充：这里以删除 test 目录和里面的文件为例）</p>



<h4>3.1.2 交互式解压加密文件或目录</h4>



<pre class="wp-block-code"><code># unzip test2.zip
Archive:  test2.zip
   creating: test/
&#91;test2.zip] test/test.txt password: 
 extracting: test/test.txt</code></pre>



<p>（补充：这里以解压 test2.zip （压缩）包为例）</p>



<h4>3.2 非交互式解压加密文件或目录<br>3.2.1 删除原测试目录和里面的文件</h4>



<pre class="wp-block-code"><code># rm -rf test</code></pre>



<p>（补充：这里以删除 test 目录和里面的文件为例）</p>



<h4>3.2.2 非交互式解压加密文件</h4>



<pre class="wp-block-code"><code># unzip -P eternalcenter test1.zip 
Archive:  test1.zip
   creating: test/
 extracting: test/test.txt  </code></pre>



<p>（补充：这里以解压 test2.zip （压缩）包并且解压密码为 eternalcenter 为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] Linux rm 命令的监控</title>
		<link>https://eternalcenter-2021-12.github.io/rm-monitor/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sun, 07 Nov 2021 13:29:10 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Setting (系统设置)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=18208</guid>

					<description><![CDATA[步骤一：将原来的 rm 命令进行备份 步骤二：创建一个记录 rm 命令使用的脚本 步骤三：给记录 rm 命令使用的脚本执行权限 步骤四：下次使用 rm 命令后就可以监控 /var/log/rm_command.log 日志了 （步骤略）]]></description>
										<content:encoded><![CDATA[
<h4>步骤一：将原来的 rm 命令进行备份</h4>



<pre class="wp-block-code"><code># cp /usr/bin/rm  /usr/bin/rm.original</code></pre>



<h4>步骤二：创建一个记录 rm 命令使用的脚本</h4>



<pre class="wp-block-code"><code># cat /usr/bin/rm
#!/bin/bash
log=/var/log/rm_command.log
echo "The $$ is calling rm command" &gt;&gt; $log
echo "The full command is $*" &gt;&gt; $log
echo
echo "now use this command to get more information: /bin/ps axwwo user,pid,ppid,%cpu,%mem,vsz,rss,stat,time,cmd" &gt;&gt;$log
/bin/ps axwwo user,pid,ppid,%cpu,%mem,vsz,rss,stat,time,cmd &gt;&gt;$log
/usr/bin/rm.original $*
echo "============================================================" &gt;&gt;$log</code></pre>



<h4>步骤三：给记录 rm 命令使用的脚本执行权限</h4>



<pre class="wp-block-code"><code># chmod 755 /usr/bin/rm.original</code></pre>



<h4>步骤四：下次使用 rm 命令后就可以监控 /var/log/rm_command.log 日志了</h4>



<p>（步骤略）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] SELinux  的启用 （openSUSE&#038;SUSE  版） （不建议）</title>
		<link>https://eternalcenter-2021-12.github.io/selinux-opensusesuse/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 01 Jun 2021 08:50:14 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=14516</guid>

					<description><![CDATA[软件准备： 在 SELinuxProject 的官网上下载 SELinux 策略 UseRefpolicy： https://github.com/SELinuxProject/refpolicy/wiki/UseRefpolicy 注意： 1) 如果使用此文的方法将 openSUSE&#38;SUSE 的 SELinux 设置为 Enforcing 则系统将无法设置 IP 地址2) 如果使用此文的方法开启了 SELinux 并且将所有的布尔（boolean）值开启，则系统将无法关机，开启所有布尔值的方法：# for i in semanage boolean -l &#124; awk '{print $1}'; do echo $i;setsebool -P $i 1; done 正文： 步骤目录： 步骤一：安装 SELinux 组件 步骤二：安装 SELinux 策略2.1 解压包含 SELinux 策略的压缩包2.2 将 SELinux 策略移动到 SELinux 配置文件的位置2.3 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/selinux-opensusesuse/" class="more-link">Continue reading<span class="screen-reader-text"> "[步骤] SELinux  的启用 （openSUSE&#038;SUSE  版） （不建议）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>软件准备：</h2>



<p>在 SELinuxProject 的官网上下载 SELinux 策略 UseRefpolicy：</p>



<p class="has-text-align-center"><a href="https://github.com/SELinuxProject/refpolicy/wiki/UseRefpolicy" target="_blank" rel="noreferrer noopener">https://github.com/SELinuxProject/refpolicy/wiki/UseRefpolicy</a></p>



<h2>注意：</h2>



<p>1) 如果使用此文的方法将 openSUSE&amp;SUSE 的 SELinux 设置为 Enforcing 则系统将无法设置 IP 地址<br>2) 如果使用此文的方法开启了 SELinux 并且将所有的布尔（boolean）值开启，则系统将无法关机，开启所有布尔值的方法：# for i in <code>semanage boolean -l | awk '{print $1}'</code>; do echo $i;setsebool -P $i 1; done</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>正文：</h2>



<h2>步骤目录：</h2>



<h4>步骤一：安装 SELinux 组件</h4>



<h4>步骤二：安装 SELinux 策略<br>2.1 解压包含 SELinux 策略的压缩包<br>2.2 将 SELinux 策略移动到 SELinux 配置文件的位置<br>2.3 进入到和 SELinux 策略相同目录下<br>2.4 查看 SELinux 策略的安装手册<br>2.5 创建 SELinux 策略的配置文件<br>2.6 创建 SELinux 策略<br>2.7 编译 SELinux 策略<br>2.8 安装 SELinux 策略</h4>



<h4>步骤三：配置 SELinux 配置文件<br>3.1 在 SELinux 配置文件中将 SELinux 设置为 Permissive 状态<br>3.2 在系统内核中禁止使用 AppArmor 使用 SELinux 并且将 SELinux状态设置为 Permissive<br>3.2.1 设置 grub 文件<br>3.2.2 让刚刚设置的 grub 文件生效<br>3.3 刷新系统内所有文件的标签</h4>



<h4>步骤四：重启系统让 SELinux 生效</h4>



<h2>具体的操作步骤：</h2>



<h4>步骤一：安装 SELinux 组件</h4>



<pre class="wp-block-code"><code># zypper in libselinux1 libsemanage1 libsepol-devel libsepol1 libselinux-devel mcstrans libselinux1-32bit policycoreutils checkpolicy libsemanage-devel setools-tcl setools-libs setools-java setools-devel setools-console selinux-tools python3-policycoreutils python3-selinux python3-semanage python3-setools restorecond</code></pre>



<h4>步骤二：安装 SELinux 策略<br>2.1 解压包含 SELinux 策略的压缩包</h4>



<pre class="wp-block-code"><code># tar -xvf refpolicy-2.20210203.tar.bz2</code></pre>



<p>（补充：这里以解压 refpolicy-2.20210203.tar.bz2 压缩包为例）</p>



<h4>2.2 将 SELinux 策略移动到 SELinux 配置文件的位置</h4>



<pre class="wp-block-code"><code># mv refpolicy /etc/selinux/</code></pre>



<h4>2.3 进入到和 SELinux 策略相同目录下</h4>



<pre class="wp-block-code"><code># cd /etc/selinux/refpolicy/</code></pre>



<h4>2.4 查看 SELinux 策略的安装手册</h4>



<pre class="wp-block-code"><code># cat INSTALL</code></pre>



<h4>2.5 创建 SELinux 策略的配置文件</h4>



<pre class="wp-block-code"><code># make conf</code></pre>



<h4>2.6 创建 SELinux 策略</h4>



<pre class="wp-block-code"><code># make policy</code></pre>



<h4>2.7 编译 SELinux 策略</h4>



<pre class="wp-block-code"><code># make install</code></pre>



<h4>2.8 安装 SELinux 策略</h4>



<pre class="wp-block-code"><code># make load</code></pre>



<h4>步骤三：配置 SELinux 配置文件<br>3.1 在 SELinux 配置文件中将 SELinux 设置为 Permissive 状态</h4>



<pre class="wp-block-code"><code># vim /etc/selinux/config</code></pre>



<p>创建以下内容：</p>



<pre class="wp-block-code"><code># This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=refpolicy</code></pre>



<h4>3.2 在系统内核中禁止使用 AppArmor 使用 SELinux 并且将 SELinux状态设置为 Permissive<br>3.2.1 设置 grub 文件</h4>



<pre class="wp-block-code"><code># vim /etc/default/grub</code></pre>



<p>在这一行里：</p>



<pre class="wp-block-code"><code>GRUB_CMDLINE_LINUX_DEFAULT="......"</code></pre>



<pre class="wp-block-code"><code>添加以下内容：</code></pre>



<pre class="wp-block-code"><code>GRUB_CMDLINE_LINUX_DEFAULT="...... security=selinux selinux=1 enforcing=0"</code></pre>



<h4>3.2.2 让刚刚设置的 grub 文件生效</h4>



<pre class="wp-block-code"><code># grub2-mkconfig -o /boot/grub2/grub.cfg</code></pre>



<h4>3.3 刷新系统内所有文件的标签</h4>



<pre class="wp-block-code"><code># restorecon -Rp /</code></pre>



<h4>步骤四：重启系统让 SELinux 生效</h4>



<pre class="wp-block-code"><code># reboot</code></pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2>参考文献：</h2>



<p class="has-text-align-center">https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-selinux.html</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux SELinux 状态的设置</title>
		<link>https://eternalcenter-2021-12.github.io/selinux-state/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 31 May 2021 13:37:41 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=14456</guid>

					<description><![CDATA[内容目录： 内容一：SELinux 的状态 内容二：永久切换 SELinux 状态2.1 将 SELinux 永久切换至 Disabled 状态2.1.1 修改 SELinux 配置文件2.1.2 重启系统2.1.3 查看 SELinux 状态2.2 将 SELinux 永久切换至 Permissive 状态2.2.1 修改 SELinux 配置文件2.2.2 重启系统2.2.3 查看 SELinux 状态2.3 将 SELinux 永久切换至 Enforcing 状态2.3.1 修改 SELinux 配置文件2.3.2 重启系统2.3.3 查看 SELinux 状态 内容三：临时切换 SELinux 状态3.1 临时切换到 Permissive 状态3.1.1 临时切换到 Permissive 状态3.1.2 查看 SELinux 状态3.2 临时切换到 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/selinux-state/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux SELinux 状态的设置"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>内容目录：</h2>



<h4>内容一：SELinux 的状态</h4>



<h4>内容二：永久切换 SELinux 状态<br>2.1 将 SELinux 永久切换至 Disabled 状态<br>2.1.1 修改 SELinux 配置文件<br>2.1.2 重启系统<br>2.1.3 查看 SELinux 状态<br>2.2 将 SELinux 永久切换至 Permissive 状态<br>2.2.1 修改 SELinux 配置文件<br>2.2.2 重启系统<br>2.2.3 查看 SELinux 状态<br>2.3 将 SELinux 永久切换至 Enforcing 状态<br>2.3.1 修改 SELinux 配置文件<br>2.3.2 重启系统<br>2.3.3 查看 SELinux 状态</h4>



<h4>内容三：临时切换 SELinux 状态<br>3.1 临时切换到 Permissive 状态<br>3.1.1 临时切换到 Permissive 状态<br>3.1.2 查看 SELinux 状态<br>3.2 临时切换到 Enforcing 状态<br>3.2.1 临时切换到 Enforcing 状态<br>3.2.2 查看 SELinux 状态</h4>



<h2>具体的内容：</h2>



<h4>内容一：SELinux 的状态</h4>



<p>1) Disabled：完全关闭 SELinux<br>2) Permissive：即使违反了策略也依旧可以执行，但是违反策略的记录会被记录在日志中<br>3) Enforcing：如果违反了策略就不能之行</p>



<h4>内容二：永久切换 SELinux 状态<br>2.1 将 SELinux 永久切换至 Disabled 状态<br>2.1.1 修改 SELinux 配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/selinux/config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
SELINUX=......
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
SELINUX=disabled
......</code></pre>



<h4>2.1.2 重启系统</h4>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4>2.1.3 查看 SELinux 状态</h4>



<pre class="wp-block-code"><code># getenforce 
Disabled</code></pre>



<h4>2.2 将 SELinux 永久切换至 Permissive 状态<br>2.2.1 修改 SELinux 配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/selinux/config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
SELINUX=......
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
SELINUX=permissive
......</code></pre>



<h4>2.2.2 重启系统</h4>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4>2.2.3 查看 SELinux 状态</h4>



<pre class="wp-block-code"><code># getenforce 
Permissive</code></pre>



<h4>2.3 将 SELinux 永久切换至 Enforcing 状态<br>2.3.1 修改 SELinux 配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/selinux/config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
SELINUX=......
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
SELINUX=enforcing
......</code></pre>



<h4>2.3.2 重启系统</h4>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4>2.3.3 查看 SELinux 状态</h4>



<pre class="wp-block-code"><code># getenforce 
Enforcing</code></pre>



<h4>内容三：临时切换 SELinux 状态<br>3.1 临时切换到 Permissive 状态<br>3.1.1 临时切换到 Permissive 状态</h4>



<pre class="wp-block-code"><code># setenfoce 0</code></pre>



<p>（<br>注意：<br>1) 系统重启后失效<br>2) 只能从 Enforcing 状态切换到 Permissive 状态<br>）</p>



<h4>3.1.2 查看 SELinux 状态</h4>



<pre class="wp-block-code"><code># getenforce 
Permissive</code></pre>



<h4>3.2 临时切换到 Enforcing 状态<br>3.2.1 临时切换到 Enforcing 状态</h4>



<pre class="wp-block-code"><code># setenfoce 1</code></pre>



<p>（<br>注意：<br>1) 系统重启后失效<br>2) 只能从 Permissive 状态切换到 Enforcing 状态<br>）</p>



<h4>3.2.2 查看 SELinux 状态</h4>



<pre class="wp-block-code"><code># getenforce 
Enforcing</code></pre>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[步骤] openSUSE&#038;SUSE AIDE 的使用 （高级入侵检测环境：Adevanced Intrusion Detection Environment）</title>
		<link>https://eternalcenter-2021-12.github.io/aide/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 11 Jan 2021 07:57:13 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=13210</guid>

					<description><![CDATA[步骤一：安装 AIDE 步骤二：生成 AIDE 的配置文件2.1 生成 AIDE 配置文件的模板 2.2 将 AIDE 配置文件的模板转换成配置文件 步骤三：使用 AIDE （补充：AIDE 要检查哪些文件不检查哪些文件可以在 /etc/aide.conf 中设置）]]></description>
										<content:encoded><![CDATA[
<h4>步骤一：安装 AIDE</h4>



<pre class="wp-block-code"><code># zypper -n install aide</code></pre>



<h4>步骤二：生成 AIDE 的配置文件<br>2.1 生成 AIDE 配置文件的模板</h4>



<pre class="wp-block-code"><code># /usr/bin/aide --init
AIDE initialized database at /var/lib/aide/aide.db.new

Number of entries:      62624</code></pre>



<h4>2.2 将 AIDE 配置文件的模板转换成配置文件</h4>



<pre class="wp-block-code"><code># mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db</code></pre>



<h4>步骤三：使用 AIDE</h4>



<pre class="wp-block-code"><code># /usr/bin/aide --check
AIDE found differences between database and filesystem!!

Summary:
  Total number of entries:      62623
  Added entries:                0
  Removed entries:              1
  Changed entries:              0</code></pre>



<p>（补充：AIDE 要检查哪些文件不检查哪些文件可以在 /etc/aide.conf 中设置）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux acl 权限</title>
		<link>https://eternalcenter-2021-12.github.io/acl/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Mon, 27 Jul 2020 14:13:44 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Privilege (系统权限)]]></category>
		<category><![CDATA[System Privilege Security (系统权限安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<category><![CDATA[System User & System Privilege (系统用户 & 系统权限)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=10342</guid>

					<description><![CDATA[案例目录： 案例一：给某一个文件或目录添加 acl1.1 给某一个文件或目录添加一个用户的 acl1.2 给某一个文件或目录添加一个组的 acl1.3 递归给某一个目录和目录里的所有内容添加一个 acl 案例二：删除某一个文件或目录的 acl2.1 删除某一个文件或目录一个用户的 acl2.2 删除某一个文件或目录一个组的 acl2.3 删除某一个文件或目录的所有 acl2.4 递归删除某一个文件或目录的 acl2.5 递归删除某一个文件或目录的所有 acl 案例三：查看某一个文件或目录的 acl 案例四：备份和还原某一个文件或目录的 acl4.1 备份某一个文件或目录的 acl4.2 还原某一给文件或目录的 acl 具体的案例： 案例一：给某一个文件或目录添加 acl1.1 给某一个文件或目录添加一个用户的 acl （补充：这里以在 /var 目录上给 zhumingyu 用户设置读和执行的 acl 权限为例） 1.2 给某一个文件或目录添加一个组的 acl （补充：这里以在 /var 目录上给 zhumingyu 组设置读和执行的 acl 权限为例） 1.3 递归给某一个目录和目录里的所有内容添加一个 acl （补充：这里以在 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/acl/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux acl 权限"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>案例目录：</h2>



<h4>案例一：给某一个文件或目录添加 acl<br>1.1 给某一个文件或目录添加一个用户的 acl<br>1.2 给某一个文件或目录添加一个组的 acl<br>1.3 递归给某一个目录和目录里的所有内容添加一个 acl</h4>



<h4>案例二：删除某一个文件或目录的 acl<br>2.1 删除某一个文件或目录一个用户的 acl<br>2.2 删除某一个文件或目录一个组的 acl<br>2.3 删除某一个文件或目录的所有 acl<br>2.4 递归删除某一个文件或目录的 acl<br>2.5 递归删除某一个文件或目录的所有 acl</h4>



<h4>案例三：查看某一个文件或目录的 acl</h4>



<h4>案例四：备份和还原某一个文件或目录的 acl<br>4.1 备份某一个文件或目录的 acl<br>4.2 还原某一给文件或目录的 acl</h4>



<h2>具体的案例：</h2>



<h4>案例一：给某一个文件或目录添加 acl<br>1.1 给某一个文件或目录添加一个用户的 acl</h4>



<pre class="wp-block-code"><code># setfacl -m u:zhumingyu:r-x /var</code></pre>



<p>（补充：这里以在 /var 目录上给 zhumingyu 用户设置读和执行的 acl 权限为例）</p>



<h4>1.2 给某一个文件或目录添加一个组的 acl</h4>



<pre class="wp-block-code"><code># setfacl -m g:zhumingyu:r-x /var</code></pre>



<p>（补充：这里以在 /var 目录上给 zhumingyu 组设置读和执行的 acl 权限为例）</p>



<h4>1.3 递归给某一个目录和目录里的所有内容添加一个 acl</h4>



<pre class="wp-block-code"><code># setfacl -Rm u:zhumingyu:r-x /var</code></pre>



<p>（补充：这里以在 /var 目录上递归给 zhumingyu 组设置读和执行的 acl 权限为例）</p>



<h4>案例二：删除某一个文件或目录的 acl<br>2.1 删除某一个文件或目录一个用户的 acl</h4>



<pre class="wp-block-code"><code># setfacl -x u:zhumingyu /var</code></pre>



<p>（补充：这里以在 /var 目录上删除 zhumingyu 用户的 acl 权限为例）</p>



<h4>2.2 删除某一个文件或目录一个组的 acl</h4>



<pre class="wp-block-code"><code># setfacl -x g:zhumingyu /var</code></pre>



<p>（补充：这里以在 /var 目录上删除 zhumingyu 组的 acl 权限为例）</p>



<h4>2.3 删除某一个文件或目录的所有 acl</h4>



<pre class="wp-block-code"><code># setfacl -b /var</code></pre>



<p>（补充：这里以在 /var 目录上删除所有 acl 权限为例）</p>



<h4>2.4 递归删除某一个文件或目录的 acl</h4>



<pre class="wp-block-code"><code># setfacl -Rx u:zhumingyu:r-x /var</code></pre>



<p>（补充：这里以在 /var 目录上递归删除 zhumingyu 用户的 acl 权限为例）</p>



<h4>2.5 递归删除某一个文件或目录的所有 acl</h4>



<pre class="wp-block-code"><code># setfacl -Rb /var</code></pre>



<p>（补充：这里以在 /var 目录上递归删除所有 acl 权限为例）</p>



<h4>案例三：查看某一个文件或目录的 acl</h4>



<pre class="wp-block-code"><code># getfacl /var</code></pre>



<p>（补充：这里以查看 /var 目录的 acl 权限为例）</p>



<h4>案例四：备份和还原某一个文件或目录的 acl<br>4.1 备份某一个文件或目录的 acl</h4>



<pre class="wp-block-code"><code># getfacl -R /var > /acl.backup</code></pre>



<p>（补充：这里以备份 /var 目录的 acl 权限为例）</p>



<h4>4.2 还原某一给文件或目录的 acl</h4>



<pre class="wp-block-code"><code># setfacl --restore /acl.backup</code></pre>



<p>（补充：这里以还原 /var 目录的 acl 权限为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux SELinux 标签的设置</title>
		<link>https://eternalcenter-2021-12.github.io/selinux-label/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 25 Jul 2020 07:11:03 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=10257</guid>

					<description><![CDATA[内容目录： 内容一：开启 SELinux 标签1.1 修改 SELinux 配置文件1.2 重启系统 内容二：SELinux 的常见特性2.1 SELinux 特性一：创建的文件或目录会自动继承其父目录的 SELinux 标签2.1.1 在 /var/www/html/ 目录下新创建 index.html 文件2.1.2 查看 /var/www/html/ 目录的 SELinux 标签2.1.3 查看新生成的 /var/www/html/index.html 标签2.2 SELinux 特性二：移动文件或目录和保留属性复制文件或目录不会改变其 SELinux 标签，普通复制会改变 SELinux 标签2.2.1 在 /tmp/ 目录下新创建 file1，file2，file3 文件2.2.2 查看 ls -Zd /tmp/ 目录的 SELinux 标签2.2.3 查看新创建文件的标签2.2.4 将 /tmp/file1 复制到 /var/www/html/2.2.5 将 /tmp/file2 移动到 /var/www/html/2.2.6 将 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/selinux-label/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux SELinux 标签的设置"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>内容目录：</h2>



<h4>内容一：开启 SELinux 标签<br>1.1 修改 SELinux 配置文件<br>1.2 重启系统</h4>



<h4>内容二：SELinux 的常见特性<br>2.1 SELinux 特性一：创建的文件或目录会自动继承其父目录的 SELinux 标签<br>2.1.1 在 /var/www/html/ 目录下新创建 index.html 文件<br>2.1.2 查看 /var/www/html/ 目录的 SELinux 标签<br>2.1.3 查看新生成的 /var/www/html/index.html 标签<br>2.2 SELinux 特性二：移动文件或目录和保留属性复制文件或目录不会改变其 SELinux 标签，普通复制会改变 SELinux 标签<br>2.2.1 在 /tmp/ 目录下新创建 file1，file2，file3 文件<br>2.2.2 查看 ls -Zd /tmp/ 目录的 SELinux 标签<br>2.2.3 查看新创建文件的标签<br>2.2.4 将 /tmp/file1 复制到 /var/www/html/<br>2.2.5 将 /tmp/file2 移动到 /var/www/html/<br>2.2.6 将 /tmp/file2 复制到 /var/www/html/，并使用 -a 选项保留文件属性<br>2.2.7 查看这些文件的 SELinux 标签</h4>



<h4>内容三：查看某个文件或目录 SELinux 标签<br>3.1 查看某个文件 SELinux 标签<br>3.2 查看某个目录 SELinux 标签<br>3.3 查看某个进程 SELinux 标签</h4>



<h4>内容四：查看所有 SELinux 标签<br>4.1 查看所有文件和目录的 SELinux 标签<br>4.2 查看所有端口的 SELinux 标签<br>4.3 查看所有进程的 SELinux 标签</h4>



<h4>内容五：设置 SELinux 标签<br>5.1 设置文件和目录 SELinux 标签<br>5.1.1 使用 semanage fcontext 命令和 restorecon 命令设置文件和目录的 SELinux 标签<br>5.1.1.1 semanage fcontext 命令的常用选项<br>5.1.1.2 使用 semanage fcontext 命令和 restorecon 命令设置文件和目录的 SELinux 标签<br>5.1.1.2.1 使用 smanage fcontext 命令设置 SELinux 标签<br>5.1.1.2.2 使用 restorecon 命令修改默认上下文<br>5.1.2 使用 chcon 命令设置 SELinux 标签<br>5.2 设置端口 SELinux</h4>



<h2>具体的内容：</h2>



<h4>内容一：开启 SELinux 标签<br>1.1 修改 SELinux 配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/selinux/config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
SELINUX=disabled
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
SELINUX=enforcing
......</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>......
SELINUX=perssive
......</code></pre>



<h4>1.2 重启系统</h4>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4>内容二：SELinux 的常见特性<br>2.1 SELinux 特性一：创建的文件或目录会自动继承其父目录的 SELinux 标签<br>2.1.1 在 /var/www/html/ 目录下新创建 index.html 文件</h4>



<pre class="wp-block-code"><code># echo website &gt; /var/www/html/index.html</code></pre>



<p>（补充：这里以在 /var/www/html/ 目录下生成 index.html 文件为例）</p>



<h4>2.1.2 查看 /var/www/html/ 目录的 SELinux 标签</h4>



<pre class="wp-block-code"><code># ls -dZ /var/www/html/
unconfined_u:object_r:httpd_sys_content_t:s0 index.html</code></pre>



<h4>2.1.3 查看新生成的 /var/www/html/index.html 标签</h4>



<pre class="wp-block-code"><code># ls -Z /var/www/html/index.html/index.html 
unconfined_u:object_r:httpd_sys_content_t:s0 index.html</code></pre>



<p>（补充：从内容 1.1.2 和内容 1.1.3 命令的结果可以看出新生成的文件或其父目录的 SELinux 标签一致）</p>



<h4>2.2 SELinux 特性二：移动文件或目录和保留属性复制文件或目录不会改变其 SELinux 标签，普通复制会改变 SELinux 标签<br>2.2.1 在 /tmp/ 目录下新创建 file1，file2，file3 文件</h4>



<pre class="wp-block-code"><code># touch /tmp/file{1,2,3}</code></pre>



<h4>2.2.2 查看 ls -Zd /tmp/ 目录的 selinux 标签</h4>



<pre class="wp-block-code"><code># ls -Zd /tmp/
unconfined_u:object_r:user_tmp_t:s0 /tmp/</code></pre>



<h4>2.2.3 查看新创建文件的标签</h4>



<pre class="wp-block-code"><code># ls -Z /tmp/file*
unconfined_u:object_r:user_tmp_t:s0 /tmp/file1  unconfined_u:object_r:user_tmp_t:s0 /tmp/file2
unconfined_u:object_r:user_tmp_t:s0 /tmp/file3</code></pre>



<h4>2.2.4 将 /tmp/file1 复制到 /var/www/html/</h4>



<pre class="wp-block-code"><code># cp /tmp/file1 /var/www/html/</code></pre>



<h4>2.2.5 将 /tmp/file2 移动到 /var/www/html/</h4>



<pre class="wp-block-code"><code># mv /tmp/file2 /var/www/html/</code></pre>



<h4>2.2.6 将 /tmp/file2 复制到 /var/www/html/，并使用 -a 选项保留文件属性</h4>



<pre class="wp-block-code"><code># cp -a /tmp/file3 /var/www/html/</code></pre>



<h4>2.2.7 查看这些文件的 SELinux 标签</h4>



<pre class="wp-block-code"><code># ls -Z /var/www/html/file*
unconfined_u:object_r:httpd_sys_content_t:s0 file1           unconfined_u:object_r:user_tmp_t:s0 file3
unconfined_u:object_r:user_tmp_t:s0 file2</code></pre>



<p>（补充：从内容 2.2.3 和内容 2.2.7 命令的结果可以看出只有普通复制会改变 SELinux 标签 ）</p>



<h4>内容三：查看某个文件、目录或进程 SELinux 标签<br>3.1 查看某个文件 SELinux 标签</h4>



<pre class="wp-block-code"><code># ls -Z &lt;file&gt;</code></pre>



<h4>3.2 查看某个目录 SELinux 标签</h4>



<pre class="wp-block-code"><code># ls -Zd &lt;directory&gt;</code></pre>



<h4>3.3 查看某个进程 SELinux 标签</h4>



<pre class="wp-block-code"><code># ps -auxZ | grep &lt;process&gt;</code></pre>



<h4>内容四：查看所有 SELinux 标签<br>4.1 查看所有文件和目录的 SELinux 标签</h4>



<pre class="wp-block-code"><code># semanage fcontext -l</code></pre>



<p>（注意：需要单独安装 policycoreutils-python-utils 后才能使用 semanage 命令）</p>



<h4>4.2 查看所有端口的 SELinux 标签</h4>



<pre class="wp-block-code"><code># semanage port -l</code></pre>



<p>（注意：需要单独安装 policycoreutils-python-utils 后才能使用 semanage 命令）</p>



<h4>4.3 查看所有进程的 SELinux 标签</h4>



<pre class="wp-block-code"><code># ps -auxZ</code></pre>



<h4>内容五：设置 SELinux 标签<br>5.1 设置文件和目录 SELinux 标签<br>5.1.1 使用 semanage fcontext 命令和 restorecon 命令设置文件和目录的 SELinux 标签<br>5.1.1.1 semanage fcontext 命令的常用选项</h4>



<p>1) -a 添加或变更 SELinux 标签<br>2) -d 删除 SELinux 标签<br>3) -l 查看所有的 SELinux 标签<br>4) -t 指定上下文 SELinux 标签<br>5) -v 显示修改 SELinux 标签的内容<br>6) -R 递归设置 SELinux 标签<br>7) -m 变更 SELinux 标签</p>



<h4>5.1.1.2 使用 semanage fcontext 命令和 restorecon 命令设置文件和目录的 SELinux 标签<br>5.1.1.2.1 使用 smanage fcontext 命令设置 SELinux 标签</h4>



<pre class="wp-block-code"><code># semanage fcontext -a -t httpd_sys_content_t "/tmp(/.*)?"</code></pre>



<p>（补充：这里以将 /tmp(/.*) 的 SELinux 标签设置为 httpd_sys_content_t 为例）</p>



<p>（注意：需要单独安装 policycoreutils-python-utils 后才能使用 semanage 命令）</p>



<h4>5.1.1.2.2 使用 restorecon 命令修改默认上下文</h4>



<pre class="wp-block-code"><code># restorecon -Rv /tmp
Relabeled /tmp from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0</code></pre>



<h4>5.1.2 使用 chcon 命令设置 SELinux 标签</h4>



<pre class="wp-block-code"><code># chcon -t httpd_sys_content_t /tmp/*</code></pre>



<p>（补充：这里以将 /tmp/* 的 SELinux 标签设置为 httpd_sys_content_t 为例）</p>



<h4>5.2 设置端口 SELinux</h4>



<pre class="wp-block-code"><code># semanage port -a -t http_port_t -p tcp 82</code></pre>



<p>（补充：这里以将 TCP 82 端口的 SELinux 标签设置为 http_port_t 为例）</p>



<p>（注意：需要单独安装 policycoreutils-python-utils 后才能使用 semanage 命令）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux SELinux 布尔 （boolean） 值的设置</title>
		<link>https://eternalcenter-2021-12.github.io/selinux-boolean/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 16 Jul 2020 11:56:09 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Log (系统日志)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Port Security (系统端口安全)]]></category>
		<category><![CDATA[System Process Security (系统进程安全)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Security Log (系统安全日志)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=10063</guid>

					<description><![CDATA[内容目录： 内容一：开启 SELinux 布尔（boolean）值1.1 查看当前 SELinux 状态1.2 将 SELinux 的状态设置为 Enforcing 以开启布尔（boolean）值1.2.1 当当前 SELinux 的状态为 Disabled 时开启布尔（boolean）值的方法1.2.1.1 修改 SELinux 配置文件1.2.1.2 重启系统1.2.2 当当前 SELinux 的状态为 Perssive 时开启布尔（boolean）值的方法 内容二：查看所有 SELinux 布尔（boolean）值 内容三：布尔（boolean）值的管理3.1 允许某一个 SELinux 布尔（boolean）值开启3.1.1 临时允许某一个 SELinux 布尔（boolean）值开启3.1.1.1 临时允许某一个 SELinux 布尔（boolean）值开启的格式3.1.1.2 临时允许某一个 SELinux 布尔（boolean）值开启的案例3.1.2 永久允许某一个 SELinux 布尔（boolean）值开启3.1.2.1 永久允许某一个 SELinux 布尔（boolean）值开启的格式3.1.2.2 永久允许某一个 SELinux 布尔（boolean）值开启的案例3.2 取消某一个 SELinux 布尔（boolean）值开启3.2.1 临时取消某一个 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/selinux-boolean/" class="more-link">Continue reading<span class="screen-reader-text"> "[内容] Linux SELinux 布尔 （boolean） 值的设置"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>内容目录：</h2>



<h4>内容一：开启 SELinux 布尔（boolean）值<br>1.1 查看当前 SELinux 状态<br>1.2 将 SELinux 的状态设置为 Enforcing 以开启布尔（boolean）值<br>1.2.1 当当前 SELinux 的状态为 Disabled 时开启布尔（boolean）值的方法<br>1.2.1.1 修改 SELinux 配置文件<br>1.2.1.2 重启系统<br>1.2.2 当当前 SELinux 的状态为 Perssive 时开启布尔（boolean）值的方法</h4>



<h4>内容二：查看所有 SELinux 布尔（boolean）值</h4>



<h4>内容三：布尔（boolean）值的管理<br>3.1 允许某一个 SELinux 布尔（boolean）值开启<br>3.1.1 临时允许某一个 SELinux 布尔（boolean）值开启<br>3.1.1.1 临时允许某一个 SELinux 布尔（boolean）值开启的格式<br>3.1.1.2 临时允许某一个 SELinux 布尔（boolean）值开启的案例<br>3.1.2 永久允许某一个 SELinux 布尔（boolean）值开启<br>3.1.2.1 永久允许某一个 SELinux 布尔（boolean）值开启的格式<br>3.1.2.2 永久允许某一个 SELinux 布尔（boolean）值开启的案例<br>3.2 取消某一个 SELinux 布尔（boolean）值开启<br>3.2.1 临时取消某一个 SELinux 布尔（boolean）值开启<br>3.2.1.1 临时取消某一个 SELinux 布尔（boolean）值开启的格式<br>3.2.1.2 临时取消某一个 SELinux 布尔（boolean）值开启的案例<br>3.2.2 永久取消某一个 SELinux 布尔（boolean）值关闭<br>3.2.2.1 永久取消某一个 SELinux 布尔（boolean）值开启的格式<br>3.2.2.2 永久取消某一个 SELinux 布尔（boolean）值开启的案例</h4>



<h2>具体的操作步骤：</h2>



<h4>内容一：开启 SELinux 布尔（boolean）值<br>1.1 查看当前 SELinux 状态</h4>



<pre class="wp-block-code"><code># getenforce</code></pre>



<h4>1.2 将 SELinux 的状态设置为 Enforcing 以开启布尔（boolean）值<br>1.2.1 当当前 SELinux 的状态为 Disabled 时开启布尔（boolean）值的方法<br>1.2.1.1 修改 SELinux 配置文件</h4>



<pre class="wp-block-code"><code># vim /etc/selinux/config</code></pre>



<p>将以下内容：</p>



<pre class="wp-block-code"><code>......
SELINUX=disabled
......</code></pre>



<p>修改为：</p>



<pre class="wp-block-code"><code>......
SELINUX=enforcing
......</code></pre>



<h4>1.2.1.2 重启系统</h4>



<pre class="wp-block-code"><code># reboot</code></pre>



<h4>1.2.2 当当前 SELinux 的状态为 Perssive 时开启布尔（boolean）值的方法</h4>



<pre class="wp-block-code"><code># setenfoce 1</code></pre>



<p>（补充：系统重启后失效）</p>



<h4>内容二：查看所有 SELinux 布尔（boolean）值</h4>



<pre class="wp-block-code"><code># semanage boolean -l</code></pre>



<h4>内容三：布尔（boolean）值的管理<br>3.1 允许某一个 SELinux 布尔（boolean）值开启<br>3.1.1 临时允许某一个 SELinux 布尔（boolean）值开启<br>3.1.1.1 临时允许某一个 SELinux 布尔（boolean）值开启的格式</h4>



<pre class="wp-block-code"><code># setsebool &lt;boolean value> 1</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool &lt;boolean value> on</code></pre>



<h4>3.1.1.2 临时允许某一个 SELinux 布尔（boolean）值开启的案例</h4>



<pre class="wp-block-code"><code># setsebool httpd_can_network_connect 1</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool httpd_can_network_connect on</code></pre>



<h4>3.1.2 永久允许某一个 SELinux 布尔（boolean）值开启<br>3.1.2.1 永久允许某一个 SELinux 布尔（boolean）值开启的格式</h4>



<pre class="wp-block-code"><code># setsebool -P &lt;boolean value> 1</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool -P &lt;boolean value> on</code></pre>



<h4>3.1.2.2 永久允许某一个 SELinux 布尔（boolean）值开启的案例</h4>



<pre class="wp-block-code"><code># setsebool -P httpd_can_network_connect 1</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool -P httpd_can_network_connect on</code></pre>



<h4>3.2 取消某一个 SELinux 布尔（boolean）值开启<br>3.2.1 临时取消某一个 SELinux 布尔（boolean）值开启<br>3.2.1.1 临时取消某一个 SELinux 布尔（boolean）值开启的格式</h4>



<pre class="wp-block-code"><code># setsebool &lt;boolean value> 0</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool &lt;boolean value> off</code></pre>



<h4>3.2.1.2 临时取消某一个 SELinux 布尔（boolean）值开启的案例</h4>



<pre class="wp-block-code"><code># setsebool httpd_can_network_connect 0</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool httpd_can_network_connect off</code></pre>



<h4>3.2.2 永久取消某一个 SELinux 布尔（boolean）值关闭<br>3.2.2.1 永久取消某一个 SELinux 布尔（boolean）值开启的格式</h4>



<pre class="wp-block-code"><code># setsebool -P &lt;boolean value> 0</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool -P &lt;boolean value> off</code></pre>



<h4>3.2.2.2 永久取消某一个 SELinux 布尔（boolean）值开启的案例</h4>



<pre class="wp-block-code"><code># setsebool -P httpd_can_network_connect 0</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># setsebool -P httpd_can_network_connect off</code></pre>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 vim （文件编辑）</title>
		<link>https://eternalcenter-2021-12.github.io/vim/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Sat, 30 May 2020 13:48:55 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Operation (系统操作)]]></category>
		<category><![CDATA[System Operation & System Setting & System Software (系统操作 & 系统设置 & 系统软件)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9629</guid>

					<description><![CDATA[内容目录： 内容一：vim 简介1.1 vim 模式1.2 使用 vim1.2.1 通过 vim 打开某一个文件1.2.2 通过 vim 打开某一个文件，并自动进入到某一行 内容二：vim 在命令模式下的操作2.1 在命令模式下让光标移动2.1.1 在命令模式下让光标网上移动2.1.2 在命令模式下让光标网下移动2.1.3 在命令模式下让光标网左移动2.1.4 在命令模式下让光标网右移动2.1.5 在命令模式下让光标移动到文件的指定行数2.1.6 在命令模式下让光标移动到文件首尾2.1.6.1 在命令模式下让光标移动到文件首部2.1.6.2 在命令模式下让光标移动到文件尾部2.2 在命令模式下删除数据2.2.1 在某一行的范围内删除数据2.2.1.1 在某一行的范围内删除一个字符2.2.1.1.1 在光标所在行的范围内删除光标之后的一个字符2.2.1.1.2 在光标所在行的范围内删除光标之前的一个字符2.2.1.2 在某一行的范围内删除多个字符2.2.1.2.1 在光标所在行的范围内删除光标之后的多个字符2.2.1.2.2 在光标所在行的范围内删除光标之前的多个字符2.2.1.2.3 在光标所在行的范围内删除光标之前的所有字符2.2.1.2.4 在光标所在行的范围内删除光标之后的所有字符2.2.2 进行整行的删除2.2.2.1 删除光标所在行2.2.2.2 从光标所在行开始删除多行2.2.2.3 从光标所在行开始删除此行和后面的所有行2.2.2.4 从光标所在行开始删除此行和前面的所有行2.2.3 重复相同的删除操作2.3 在命令模式下复制数据2.3.1 在某一行的范围内复制数据2.3.1.3 在光标所在行的范围内复制光标之前的所有字符2.3.1.4 在光标所在行的范围内复制光标之后的所有字符2.3.2 进行整行的复制2.3.2.1 复制光标所在行2.3.2.2 从光标所在行开始复制多行2.3.2.3 从光标所在行开始复制此行和后面的所有行2.3.2.4 从光标所在行开始复制此行和前面的所有行2.4 在命令模式下复制数据2.4.1 从光标所在行开始向上复制2.4.2 从光标所在行开始向上复制2.5 在命令模式下进入其他模式2.5.1 在命令模式下进入输入模式2.5.2 在命令模式下进入末行模式2.5.3 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/vim/" class="more-link">Continue reading<span class="screen-reader-text"> "[命令] Linux 命令 vim （文件编辑）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>内容目录：</h2>



<h4>内容一：vim 简介<br>1.1 vim 模式<br>1.2 使用 vim<br>1.2.1 通过 vim 打开某一个文件<br>1.2.2 通过 vim 打开某一个文件，并自动进入到某一行</h4>



<h4>内容二：vim 在命令模式下的操作<br>2.1 在命令模式下让光标移动<br>2.1.1 在命令模式下让光标网上移动<br>2.1.2 在命令模式下让光标网下移动<br>2.1.3 在命令模式下让光标网左移动<br>2.1.4 在命令模式下让光标网右移动<br>2.1.5 在命令模式下让光标移动到文件的指定行数<br>2.1.6 在命令模式下让光标移动到文件首尾<br>2.1.6.1 在命令模式下让光标移动到文件首部<br>2.1.6.2 在命令模式下让光标移动到文件尾部<br>2.2 在命令模式下删除数据<br>2.2.1 在某一行的范围内删除数据<br>2.2.1.1 在某一行的范围内删除一个字符<br>2.2.1.1.1 在光标所在行的范围内删除光标之后的一个字符<br>2.2.1.1.2 在光标所在行的范围内删除光标之前的一个字符<br>2.2.1.2 在某一行的范围内删除多个字符<br>2.2.1.2.1 在光标所在行的范围内删除光标之后的多个字符<br>2.2.1.2.2 在光标所在行的范围内删除光标之前的多个字符<br>2.2.1.2.3 在光标所在行的范围内删除光标之前的所有字符<br>2.2.1.2.4 在光标所在行的范围内删除光标之后的所有字符<br>2.2.2 进行整行的删除<br>2.2.2.1 删除光标所在行<br>2.2.2.2 从光标所在行开始删除多行<br>2.2.2.3 从光标所在行开始删除此行和后面的所有行<br>2.2.2.4 从光标所在行开始删除此行和前面的所有行<br>2.2.3 重复相同的删除操作<br>2.3 在命令模式下复制数据<br>2.3.1 在某一行的范围内复制数据<br>2.3.1.3 在光标所在行的范围内复制光标之前的所有字符<br>2.3.1.4 在光标所在行的范围内复制光标之后的所有字符<br>2.3.2 进行整行的复制<br>2.3.2.1 复制光标所在行<br>2.3.2.2 从光标所在行开始复制多行<br>2.3.2.3 从光标所在行开始复制此行和后面的所有行<br>2.3.2.4 从光标所在行开始复制此行和前面的所有行<br>2.4 在命令模式下复制数据<br>2.4.1 从光标所在行开始向上复制<br>2.4.2 从光标所在行开始向上复制<br>2.5 在命令模式下进入其他模式<br>2.5.1 在命令模式下进入输入模式<br>2.5.2 在命令模式下进入末行模式<br>2.5.3 在命令模式下进入视图模式<br>2.5.3.1 以行的方式进入视图模式<br>2.5.3.2 以字符的方式进入视图模式<br>2.5.3.3 vim 字符模式的使用案例<br>2.5.4 在命令模式下进入替换模式<br>2.6 在命令模式下的其他操作<br>2.6.1 将光标所在行与下面的行合并<br>2.6.2 重复上一动作<br>2.6.3 撤销上一个动作<br>2.6.4 保存此文当并退出 vim 模式</h4>



<h4>内容三：vim 在末行模式下的操作<br>3.1 在末行模式下对当前内容进行保存并退出 vim 模式<br>3.2 在末行模式下的行号设置<br>3.2.1 设置行号<br>3.2.2 取消行号<br>3.3 在末行模式下搜索<br>3.3.1 在末行模式下搜索关键字<br>3.3.1.1 向下查找匹配的关键字<br>3.3.1.2 向上查找匹配的关键字<br>3.3.2 在末行模式下搜索行号<br>3.4 在末行模式下替换关键字的案例<br>3.5 在末行模式进入命令模式<br>3.6 在末行模式下的其他设置</h4>



<h4>内容四：vim 在输入模式下的操作<br>4.1 在输入模式下输入内容<br>4.2 在输入模式下进入命令模式</h4>



<h2>具体的内容：</h2>



<h4>内容一：vim 简介<br>1.1 vim 模式简介</h4>



<p>1) 命令模式：主要用于对文件进行批量编辑<br>2) 末行模式：主要用于保存退出文件<br>3) 输入模式：主要用于编辑文件</p>



<h4>1.2 使用 vim<br>1.2.1 通过 vim 打开某一个文件</h4>



<pre class="wp-block-code"><code># vim &lt;file&gt;</code></pre>



<p>（补充：此时将自动进入命令模式）</p>



<h4>1.2.2 通过 vim 打开某一个文件，并自动进入到某一行</h4>



<pre class="wp-block-code"><code># vim +&lt;line number&gt; &lt;file&gt;</code></pre>



<p>（补充：此时将自动进入命令模式）</p>



<h4>内容二：vim 在命令模式下的操作<br>2.1 在命令模式下让光标移动<br>2.1.1 在命令模式下让光标网上移动</h4>



<p>按下 &#8220;上方向键&#8221;</p>



<p>或者：</p>



<p>按下 &#8220;k&#8221;</p>



<p>或者：</p>



<p>按下 &#8220;&lt;任意数字&gt;&#8221; 再按下 &#8220;上方向键&#8221;</p>



<p>（注意：此方法会向上方移动对应数字个光标位）</p>



<h4>2.1.2 在命令模式下让光标网下移动</h4>



<p>按下 &#8220;下方向键&#8221;</p>



<p>或者：</p>



<p>按下 “j”</p>



<p>或者：</p>



<p>按下 &#8220;&lt;任意数字&gt;&#8221; 再按下 &#8220;下方向键&#8221;</p>



<p>（注意：此方法会向下方移动对应数字个光标位）</p>



<h4>2.1.3 在命令模式下让光标网左移动</h4>



<p>按下 &#8220;左方向键&#8221;</p>



<p>或者：</p>



<p>按下 &#8220;h&#8221;</p>



<p>或者：</p>



<p>按下 &#8220;任意数字&#8221; 之后再按 &#8220;左方向键&#8221;</p>



<p>（注意：此方法会向左方移动对应数字个光标位）</p>



<h4>2.1.4 在命令模式下让光标网右移动</h4>



<p>按下 &#8220;右方向键&#8221;</p>



<p>或者：</p>



<p>按下 &#8220;l&#8221;</p>



<p>或者：</p>



<p>按下 &#8220;&lt;任意数字&gt;&#8221; 之后再按 &#8220;右方向键&#8221;</p>



<p>（注意：此方法会向右方移动对应数字个光标位）</p>



<h4>2.1.5 在命令模式下让光标移动到文件的指定行数</h4>



<p>按下 &#8220;&lt;任意数字&gt;&#8221; 之后再按 “G”</p>



<p>（注意：此方法会让光标移动到对应数字的行）</p>



<h4>2.1.6 在命令模式下让光标移动到文件首尾<br>2.1.6.1 在命令模式下让光标移动到文件首部</h4>



<p>按下 “g” 再按下 “g”</p>



<h4>2.1.6.2 在命令模式下让光标移动到文件尾部</h4>



<p>按下 “G”</p>



<h4>2.2 在命令模式下删除数据<br>2.2.1 在某一行的范围内删除数据<br>2.2.1.1 在某一行的范围内删除一个字符<br>2.2.1.1.1 在光标所在行的范围内删除光标之后的一个字符</h4>



<p>按下 “x”</p>



<h4>2.2.1.1.2 在光标所在行的范围内删除光标之前的一个字符</h4>



<p>按下 “X”</p>



<h4>2.2.1.2 在某一行的范围内删除多个字符<br>2.2.1.2.1 在光标所在行的范围内删除光标之后的多个字符</h4>



<p>按下 “&lt;任意数字&gt;” 之后再按 “x”</p>



<p>（注意：此方法会在光标所在行的范围内从光标所在位置开始向后删除对应数字个字符）</p>



<h4>2.2.1.2.2 在光标所在行的范围内删除光标之前的多个字符</h4>



<p>按下 “&lt;任意数字&gt;” 之后再按 “X”</p>



<p>（注意：此方法会在光标所在行的范围内从光标所在位置开始向前删除对应数字个字符）</p>



<h4>2.2.1.2.3 在光标所在行的范围内删除光标之前的所有字符</h4>



<p>同时按下 “d” 和 “0”</p>



<h4>2.2.1.2.4 在光标所在行的范围内删除光标之后的所有字符</h4>



<p>同时按下 “d” 和 “$”</p>



<h4>2.2.2 进行整行的删除<br>2.2.2.1 删除光标所在行</h4>



<p>按下 “d” 之后再按 “d”</p>



<h4>2.2.2.2 从光标所在行开始删除多行</h4>



<p>按下 “&lt;任意数字&gt;” 之后再按 “d” 之后再按 “d”</p>



<p>（注意：此方法会从光标所在行开始向后删除到对应数字个行）</p>



<h4>2.2.2.3 从光标所在行开始删除此行和后面的所有行</h4>



<p>按下 “d” 之后再按 “G”</p>



<h4>2.2.2.4 从光标所在行开始删除此行和前面的所有行</h4>



<p>按下 “d” 之后再按 “1” 之后再按 “G”</p>



<p>或者：</p>



<p>按下 “d” 之后再按 “g” 之后再按 “g”</p>



<h4>2.2.3 重复相同的删除操作</h4>



<p>按下 “c”</p>



<h4>2.3 在命令模式下复制数据<br>2.3.1 在某一行的范围内复制数据<br>2.3.1.3 在光标所在行的范围内复制光标之前的所有字符</h4>



<p>同时按下 “y” 和 “0”</p>



<h4>2.3.1.4 在光标所在行的范围内复制光标之后的所有字符</h4>



<p>同时按下 “y” 和 “$”</p>



<h4>2.3.2 进行整行的复制<br>2.3.2.1 复制光标所在行</h4>



<p>按下 “y” 之后再按 “y”</p>



<h4>2.3.2.2 从光标所在行开始复制多行</h4>



<p>按下 “&lt;任意数字&gt;” 之后再按 “y” 之后再按 “y”</p>



<p>（注意：此方法会从光标所在行开始向后复制对应数字个行）</p>



<h4>2.3.2.3 从光标所在行开始复制此行和后面的所有行</h4>



<p>按下 “y” 之后再按 “G”</p>



<h4>2.3.2.4 从光标所在行开始复制此行和前面的所有行</h4>



<p>按下 “y” 之后再按 “1” 之后再按 “G”</p>



<p>或者：</p>



<p>按下 “y” 之后再按 “g” 之后再按 “g”</p>



<h4>2.4 在命令模式下复制数据<br>2.4.1 从光标所在行开始向上复制</h4>



<p>按下 “p”</p>



<h4>2.4.2 从光标所在行开始向上复制</h4>



<p>按下 “P”</p>



<h4>2.5 在命令模式下进入其他模式<br>2.5.1 在命令模式下进入输入模式</h4>



<p>1) 按下 “i”，在光标所在位置进入输入模式<br>2) 按下 “a”，在光标所在位置的后一个字符进入输入模式<br>3) 按下 “A”，在光标所在行的行尾进入插入模式<br>4) 按下 “I”，在光标所在行的行首进入插入模式<br>5) 按下 “o”，在光标所在行的下一行行首进入输入模式</p>



<h4>2.5.2 在命令模式下进入末行模式</h4>



<p>按下 “:”</p>



<h4>2.5.3 在命令模式下进入视图模式<br>2.5.3.1 以行的方式进入视图模式</h4>



<p>按下 “v”</p>



<p>或者：</p>



<p>按下 “V”</p>



<h4>2.5.3.2 以字符的方式进入视图模式</h4>



<p>同时按下 “ctrl” 和 “v”</p>



<h4>2.5.3.3 vim 字符模式的使用案例</h4>



<p>1) 在光标所在行行首，同时按下 “ctrl” 和 “v” 再选择对应的行首再按 “d” 或者 “x”，删除在这些行行首的字符<br>2) 在光标所在行行首，同时按下 “ctrl” 和 “v” 再选择对应的行首再按 “I” 再输入 &lt;想要插入的内容> 再按 “ESC” ，在这些行行首插入这些内容<br>3) 在光标所在行行首，同时按下 “ctrl” 和 “v” 再按下再按 “I” 再按 “g” 再按 “g” 再输入 &lt;想要插入的内容> 再按 “ESC” ，在光标所在行以及前面的所有行的行首插入这些内容<br>4) 在光标所在行行首，同时按下 “ctrl” 和 “v” 再按下再按 “I” 再按 “G” 再输入 &lt;想要插入的内容> 再按 “ESC” ，在这光标所在行以及后面的所有行的行首插入这些内容</p>



<h4>2.5.4 在命令模式下进入替换模式</h4>



<p>按下 “R”</p>



<h4>2.6 在命令模式下的其他操作<br>2.6.1 将光标所在行与下面的行合并</h4>



<p>按下 “J”</p>



<h4>2.6.2 重复上一动作</h4>



<p>按下 “ctrl” 和 “r”</p>



<p>或者：</p>



<p>按下 “.“</p>



<h4>2.6.3 撤销上一个动作</h4>



<p>按下 “u”</p>



<h4>2.6.4 保存此文当并退出 vim 模式</h4>



<p>按下 “Z” 和 “Z”</p>



<h4>内容三：vim 在末行模式下的操作<br>3.1 在末行模式下对当前内容进行保存并退出 vim 模式</h4>



<p>1) :w #保存当前内容<br>2) :q #退出 vim 模式<br>3) :wq #保存当前内容并退出<br>4) <img src="https://s.w.org/images/core/emoji/13.1.0/72x72/1f621.png" alt="😡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> #保存当前内容并退出<br>5) :q! #不保存当前内容并强制退出<br>6) :wq! #强制保存当前内容并退出</p>



<h4>3.2 在末行模式下的行号设置<br>3.2.1 设置行号</h4>



<pre class="wp-block-code"><code>:set nu #设置行号</code></pre>



<h4>3.2.2 取消行号</h4>



<pre class="wp-block-code"><code>:set nonu #取消行号</code></pre>



<h4>3.3 在末行模式下搜索<br>3.3.1 在末行模式下搜索关键字<br>3.3.1.1 向下查找匹配的关键字</h4>



<p>:/&lt;关键字&gt; 之后按 “n” 或者 “N” 查看下一个匹配的关键字</p>



<h4>3.3.1.2 向上查找匹配的关键字</h4>



<p>:？&lt;关键字&gt; 之后按 “n” 或者 “N” 查看下一个匹配的关键字</p>



<h4>3.3.2 在末行模式下搜索行号</h4>



<p>:&lt;行号&gt; 之后按“回车”</p>



<h4>3.4 在末行模式下替换关键字的案例</h4>



<p>1) :s /&lt;旧关键字>/&lt;新关键字> #以 &lt;新关键字> 替换光标所在行的第一个 &lt;旧关键字><br>2) :s /&lt;旧关键字>/&lt;新关键字>/g #以 &lt;新关键字> 替换光标所在行的所有 &lt;旧关键字><br>3) :1,5 s/&lt;旧关键字>/&lt;新关键字>/g #以 &lt;新关键字> 替换从 1 到 5 行的所有 &lt;旧关键字><br>4) :,+5 s/&lt;旧关键字>/&lt;新关键字>/g #以 &lt;新关键字> 替换从光标所在行开始 5 行的所有 &lt;旧关键字><br>5) :7,%s/&lt;旧关键字>/&lt;新关键字>/g #以 &lt;新关键字> 替换倒数第 7 行到最后 1 行的所有 &lt;旧关键字><br>6) :%s/&lt;旧关键字>/&lt;新关键字>/g #以 &lt;新关键字> 替换全文的所有 &lt;旧关键字></p>



<h4>3.5 在末行模式进入命令模式</h4>



<p>:按 “ESC”</p>



<h4>3.6 在末行模式下的其他设置</h4>



<p>1) :w /&lt;新文件名>，将当前内容另存为另一个文件<br>2) :r /&lt;文件名>，读取 &lt;文件名> 里的内容到文本并直接插入到光标所在位置<br>3) :! &lt;命令>，在 vim 的命末行模式时使用 Linux 命令</p>



<h4>内容四：vim 在输入模式下的操作<br>4.1 在输入模式下输入内容</h4>



<p>正常键入内容即可</p>



<h4>4.2 在输入模式下进入命令模式</h4>



<p>按 “ESC”</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[内容] Linux 通佩符</title>
		<link>https://eternalcenter-2021-12.github.io/wildcard/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 28 May 2020 14:38:25 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9566</guid>

					<description><![CDATA[内容一：Linux 通佩符1.1 匹配任意一个字符 1.2 匹配任意多个字符 1.3 匹配任意多个字符中的一个 或者： 1.4 不匹配任意多个字符中的一个 或者： 1.5 匹配一段连续的字符 内容二：Linux 通佩符的使用案例2.1 案例一：多循环匹配文件或目录 2.2 案例二：匹配所有文件和目录，包括隐藏文件和目录]]></description>
										<content:encoded><![CDATA[
<h4>内容一：Linux 通佩符<br>1.1 匹配任意一个字符</h4>



<pre class="wp-block-code"><code>？</code></pre>



<h4>1.2 匹配任意多个字符</h4>



<pre class="wp-block-code"><code>*</code></pre>



<h4>1.3 匹配任意多个字符中的一个</h4>



<pre class="wp-block-code"><code>&#91;&lt;character&gt;&lt;character&gt;&lt;character&gt;]</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>{&lt;character&gt;,&lt;character&gt;,&lt;character&gt;}</code></pre>



<h4>1.4 不匹配任意多个字符中的一个</h4>



<pre class="wp-block-code"><code>&#91;^&lt;character&gt;&lt;character&gt;&lt;character&gt;]</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code>&#91;!&lt;character&gt;&lt;character&gt;&lt;character&gt;]</code></pre>



<h4>1.5 匹配一段连续的字符</h4>



<pre class="wp-block-code"><code>{&lt;head character&gt;...&lt;tail character&gt;}</code></pre>



<h4>内容二：Linux 通佩符的使用案例<br>2.1 案例一：多循环匹配文件或目录</h4>



<pre class="wp-block-code"><code># touch {a..b}{1..3}.txt
# ls
a1.txt  a2.txt  a3.txt  b1.txt  b2.txt  b3.txt</code></pre>



<h4>2.2 案例二：匹配所有文件和目录，包括隐藏文件和目录</h4>



<pre class="wp-block-code"><code># cd /tmp
# tar -zcvf /home/zhumingyu/all.tar.gz .&#91;!.]* *</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 cd （目录切换）</title>
		<link>https://eternalcenter-2021-12.github.io/cd/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Thu, 28 May 2020 13:58:38 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9564</guid>

					<description><![CDATA[内容一：进入到某一个目录 内容二：进入当前用户的家目录 或者： 内容三：返回之前的目录 内容四：进入当前目录 内容五：进入当前目录的上一级目录]]></description>
										<content:encoded><![CDATA[
<h4>内容一：进入到某一个目录</h4>



<pre class="wp-block-code"><code># cd &lt;directory></code></pre>



<h4>内容二：进入当前用户的家目录</h4>



<pre class="wp-block-code"><code># cd</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># cd ~</code></pre>



<h4>内容三：返回之前的目录</h4>



<pre class="wp-block-code"><code># cd -</code></pre>



<h4>内容四：进入当前目录</h4>



<pre class="wp-block-code"><code># cd .</code></pre>



<h4>内容五：进入当前目录的上一级目录</h4>



<pre class="wp-block-code"><code># cd ..</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 less （查看文本） （多功能版）</title>
		<link>https://eternalcenter-2021-12.github.io/less/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 27 May 2020 15:03:02 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9550</guid>

					<description><![CDATA[内容一：less 命令的使用格式 （补充：这样就会进入到这个文件的 less 查看模式） 内容二：进入 less 查看模式后的可用操作 1) 按下 “空格”，查看文件后面的内容2) 按下 “page up”，翻页文件后面的内容3) 按下 “page up”，翻一页到文件前面的内容4) 按下 “q”，退出 less 查看模式]]></description>
										<content:encoded><![CDATA[
<h4>内容一：less 命令的使用格式</h4>



<pre class="wp-block-code"><code># less &lt;file&gt;</code></pre>



<p>（补充：这样就会进入到这个文件的 less 查看模式）</p>



<h4>内容二：进入 less 查看模式后的可用操作</h4>



<p>1) 按下 “空格”，查看文件后面的内容<br>2) 按下 “page up”，翻页文件后面的内容<br>3) 按下 “page up”，翻一页到文件前面的内容<br>4) 按下 “q”，退出 less 查看模式</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 more （查看文本）</title>
		<link>https://eternalcenter-2021-12.github.io/more/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 27 May 2020 15:00:45 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9548</guid>

					<description><![CDATA[内容一：more 命令的格式 （补充：这样就会进入到这个文件的 more 查看模式） 内容二：进入 more 查看模式后的可用操作 1) 按下 “空格”，查看文件后面的内容2) 按下 “q”，退出 more 查看模式]]></description>
										<content:encoded><![CDATA[
<h4>内容一：more 命令的格式</h4>



<pre class="wp-block-code"><code># more &lt;file&gt;</code></pre>



<p>（补充：这样就会进入到这个文件的 more 查看模式）</p>



<h4>内容二：进入 more 查看模式后的可用操作</h4>



<p>1) 按下 “空格”，查看文件后面的内容<br>2) 按下 “q”，退出 more 查看模式</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 head （打印文本的前几行）</title>
		<link>https://eternalcenter-2021-12.github.io/head/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 27 May 2020 14:57:32 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9546</guid>

					<description><![CDATA[内容一：head 命令的格式 内容二：head 命令的使用案例2.1 案例一 （补充：这里以查看 /etc/passwd 文件的前 5 行为例） 2.2 案例二 （补充：这里以查看 /etc/passwd 文件的前 2 行为例） 2.3 案例三 （补充：这里以查看 /etc/passwd 文件的除后 2 行的所有行为例）]]></description>
										<content:encoded><![CDATA[
<h4>内容一：head 命令的格式</h4>



<pre class="wp-block-code"><code># head -&lt;number&gt; &lt;file&gt;</code></pre>



<pre class="wp-block-code"><code>（
补充：
1) 这里的数字是几就是显示文件里的开头几行
2) 不输入数字则默认显示文件里的开头 10 行
）</code></pre>



<h4>内容二：head 命令的使用案例<br>2.1 案例一</h4>



<pre class="wp-block-code"><code># head -5 /etc/passwd</code></pre>



<p>（补充：这里以查看 /etc/passwd 文件的前 5 行为例）</p>



<h4>2.2 案例二</h4>



<pre class="wp-block-code"><code># head -n +2 /etc/passwd</code></pre>



<p>（补充：这里以查看 /etc/passwd 文件的前 2 行为例）</p>



<h4>2.3 案例三</h4>



<pre class="wp-block-code"><code># head -n -2 /etc/passwd</code></pre>



<p>（补充：这里以查看 /etc/passwd 文件的除后 2 行的所有行为例）</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 tail （打印文本的后几行）</title>
		<link>https://eternalcenter-2021-12.github.io/tail/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 27 May 2020 14:54:55 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=9544</guid>

					<description><![CDATA[案例一：使用 tail 命令显示文件的最后 10 行 案例二：使用 tail 命令显示文件的最后 5 行 案例三：使用 tail 命令一直显示文件新增加的内容 案例四：使用 tail 命令一直显示文件新增加的内容，并只显示最新的 5 行]]></description>
										<content:encoded><![CDATA[
<h4>案例一：使用 tail 命令显示文件的最后 10 行</h4>



<pre class="wp-block-code"><code># tail /etc/passwd</code></pre>



<h4>案例二：使用 tail 命令显示文件的最后 5 行</h4>



<pre class="wp-block-code"><code># tail -5 /etc/passwd</code></pre>



<h4>案例三：使用 tail 命令一直显示文件新增加的内容</h4>



<pre class="wp-block-code"><code># tail -f /etc/passwd</code></pre>



<h4>案例四：使用 tail 命令一直显示文件新增加的内容，并只显示最新的 5 行</h4>



<pre class="wp-block-code"><code># tail -n 5 -f /etc/passwd</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 cut （打印文本的列） （转载）</title>
		<link>https://eternalcenter-2021-12.github.io/cut/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Fri, 10 Apr 2020 08:51:01 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Languages (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Basic (基础)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=8706</guid>

					<description><![CDATA[注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来]]></description>
										<content:encoded><![CDATA[
<pre class="wp-block-code"><code>cut命令

cut是一个选取命令，就是将一段数据经过分析取出我们想要的。
语法：Usage: cut OPTION... &#91;FILE]...

选项：
-b,--bytes=LIST：仅显示行中指定直接范围的内容；
-c,--characters=LIST：仅显示行中指定范围的字符；
-d,--delimiter=DELIM：指定字段的分隔符，默认的字段分隔符为“TAB”；
-f,--fields=LIST：显示指定字段的内容；
-n：与“-b”选项连用，不分割多字节字符；
--complement：选项提取指定字段之外的列；
--out-delimiter=&lt;字段分隔符&gt;：指定输出内容是的字段分割符；

补充扩展：
cut命令可以将一串字符作为列来显示，字符字段的记法：
N-：从第N个字节、字符、字段到结尾；
N-M：从第N个字节、字符、字段到第M个（包括M在内）字节、字符、字段；
-M：从第1个字节、字符、字段到第M个（包括M在内）字节、字符、字段。
上面是记法，结合下面选项将每个范围的字节、字符指定为字段：
-b 表示字节；
-c 表示字符；
-f 表示定义字段；

注：cut是竖着切（竖着分割）

&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cat a.txt 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

实例一：

&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cat a.txt 
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

取出第一列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f 1 a.txt 
root
bin
daemon
adm
lp

取出第一列和第三列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f 1,3 a.txt 
root:0
bin:1
daemon:2
adm:3
lp:4

取出第一列至第三列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f 1-3 a.txt 
root:x:0
bin:x:1
daemon:x:2
adm:x:3
lp:x:4

取出第四列和之前的所有列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f -4  a.txt 
root:x:0:0
bin:x:1:1
daemon:x:2:2
adm:x:3:4
lp:x:4:7

取出第四列和之后的所有列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f 4-  a.txt 
0:root:/root:/bin/bash
1:bin:/bin:/sbin/nologin
2:daemon:/sbin:/sbin/nologin
4:adm:/var/adm:/sbin/nologin
7:lp:/var/spool/lpd:/sbin/nologin

总结：
-d     分界符
-f 1-3 第1列至第3列
-f 1,3 第1列和第3列
-f -3  第3列和之前的内容
-f 3-  第3列号和之后的内容


实例二：

取出除第一列之外的所有列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f 1 --complement a.txt 
x:0:0:root:/root:/bin/bash
x:1:1:bin:/bin:/sbin/nologin
x:2:2:daemon:/sbin:/sbin/nologin
x:3:4:adm:/var/adm:/sbin/nologin
x:4:7:lp:/var/spool/lpd:/sbin/nologin

取出除第一列和第三列之外的所有列
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -d ":" -f 1,3 --complement a.txt 
x:0:root:/root:/bin/bash
x:1:bin:/bin:/sbin/nologin
x:2:daemon:/sbin:/sbin/nologin
x:4:adm:/var/adm:/sbin/nologin
x:7:lp:/var/spool/lpd:/sbin/nologin


实例三：

打印第一个字符到第三个字符
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -c 1-3 a.txt 
roo
bin
dae
adm
lp:

打印前面两个字符
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -c -2 a.txt 
ro
bi
da
ad
lp

打印第五个字符及后面所有的字符
&#91;root@iZwz9bhan5nqzh979qokrkZ ~]# cut -c 5- a.txt 
:x:0:0:root:/root:/bin/bash
x:1:1:bin:/bin:/sbin/nologin
on:x:2:2:daemon:/sbin:/sbin/nologin
x:3:4:adm:/var/adm:/sbin/nologin
:4:7:lp:/var/spool/lpd:/sbin/nologin
————————————————
版权声明：本文为CSDN博主「东城绝神」的原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/m0_37814112/java/article/details/80492032</code></pre>



<p>注明：所有转载内容皆直接从被转载文章网页的标题和内容的文本中复制而来</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img loading="lazy" width="1007" height="232" src="https://eternalcenter-2021-12.github.io/wp-content/uploads/2020/04/版权声明证明-cut.png" alt="" class="wp-image-8708" srcset="https://eternalcenter-2021-12.github.io/wp-content/uploads/2020/04/版权声明证明-cut.png 1007w, https://eternalcenter-2021-12.github.io/wp-content/uploads/2020/04/版权声明证明-cut-300x69.png 300w, https://eternalcenter-2021-12.github.io/wp-content/uploads/2020/04/版权声明证明-cut-768x177.png 768w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /><figcaption>CC 4.0 BY-SA 版权协议网址：https://creativecommons.org/licenses/by-sa/4.0/deed.z</figcaption></figure></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 find （查找文件或目录）</title>
		<link>https://eternalcenter-2021-12.github.io/find/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Tue, 03 Dec 2019 08:15:22 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System Directory (系统目录)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage (系统存储)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=7220</guid>

					<description><![CDATA[内容目录： 内容一：find 格式 内容二：find 选项 内容三：find 参数3.1 匹配名称的参数3.2 匹配属性的参3.3 匹配所有者的参数3.4 匹配权限的参数3.5 匹配时间的参数3.6 匹配大小的参数3.7 匹配目录的参数3.8 匹配格式化方式的参数3.9 逻辑匹配参数 内容四：find 的使用案例4.1 案例一：匹配名称的参数4.2 案例二：匹配属性的参4.3 案例三：匹配所有者的参数4.3.1 从当前目录开始查找所属主是 root 的文件和目录4.3.2 从当前目录开始查找没有所属主和所属组的文件和目录4.3.3 查找所有所属主是 natasha 的文件并将它们复制到 /root/findfiles 目录下4.4 案例四：匹配权限的参数4.4.1 从当前目录开始查找所有权限为 0777 的文件，并将其显示出来4.4.2 从当前目录开始查找权限为 222 的文件4.4.3 从当前目录开始查找有任何执行权限的文件和目录4.4.4 查找所有包含特殊权限的文件和目录4.5 案例五：匹配时间的参数4.5.1 从当前目录开始查找 10 天内被修改过的文件4.5.2 从 /var/log/mysql 目录开始查找在过去 3 天被修过的文件和目录，并在确认后将其删除4.6 案例六：匹配大小的参数4.6.1 从当前目录开始查找所有大小为 0 的文件，并将其显示出来4.6.2 从当前目录开始查找所有大小为 0 的文件4.7 &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/find/" class="more-link">Continue reading<span class="screen-reader-text"> "[命令] Linux 命令 find （查找文件或目录）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>内容目录：</h2>



<h4>内容一：find 格式</h4>



<h4>内容二：find 选项</h4>



<h4>内容三：find 参数<br>3.1 匹配名称的参数<br>3.2 匹配属性的参<br>3.3 匹配所有者的参数<br>3.4 匹配权限的参数<br>3.5 匹配时间的参数<br>3.6 匹配大小的参数<br>3.7 匹配目录的参数<br>3.8 匹配格式化方式的参数<br>3.9 逻辑匹配参数</h4>



<h4>内容四：find 的使用案例<br>4.1 案例一：匹配名称的参数<br>4.2 案例二：匹配属性的参<br>4.3 案例三：匹配所有者的参数<br>4.3.1 从当前目录开始查找所属主是 root 的文件和目录<br>4.3.2 从当前目录开始查找没有所属主和所属组的文件和目录<br>4.3.3 查找所有所属主是 natasha 的文件并将它们复制到 /root/findfiles 目录下<br>4.4 案例四：匹配权限的参数<br>4.4.1 从当前目录开始查找所有权限为 0777 的文件，并将其显示出来<br>4.4.2 从当前目录开始查找权限为 222 的文件<br>4.4.3 从当前目录开始查找有任何执行权限的文件和目录<br>4.4.4 查找所有包含特殊权限的文件和目录<br>4.5 案例五：匹配时间的参数<br>4.5.1 从当前目录开始查找 10 天内被修改过的文件<br>4.5.2 从 /var/log/mysql 目录开始查找在过去 3 天被修过的文件和目录，并在确认后将其删除<br>4.6 案例六：匹配大小的参数<br>4.6.1 从当前目录开始查找所有大小为 0 的文件，并将其显示出来<br>4.6.2 从当前目录开始查找所有大小为 0 的文件<br>4.7 案例七：匹配目录的参数<br>4.8 案例八：匹配格式化方式的参数<br>4.9 案例九：逻辑匹配参数<br>4.9.1 从当前目录开始查找以 “.txt” 结尾和以 “.dox” 结尾的文件<br>4.9.2 从当前目录开始查找权限不是 777 的文件<br>4.9.3 从当前目录开始查找权限为 2000 和 4000 的文件，并分析文件属性</h4>



<h2>具体的内容：</h2>



<h4>内容一：find 格式</h4>



<pre class="wp-block-code"><code># find &lt;directory&gt; &lt;parameter&gt; &lt;parameter&gt; ...... -print &lt;-exec|-ok&gt; &lt;command|file&gt; {&lt;command&gt;} \;</code></pre>



<h4>内容二：find 选项</h4>



<p>1) 目录 指需要查找的目录<br>2) 参数 限制匹配的条件，可以有多个<br>3) -print 将匹配的结果进行标准输出<br>4) -exec 对匹配的结果执行后面的步骤<br>5) -ok 和 -exec 的作用相同，只不过每执行一步就需要用户确认一下<br>6) command 对匹配的结果执行命令<br>7) file 对匹配的结果进行文件种类分析，后面的 {} 里的命令必须为空<br>8) 命令 对匹配结果要执行的命令</p>



<p>（注意：&lt;-exec|-ok&gt; {} \;，这是一个固定格式，谁也不能被缺少。并且 {&lt;命令&gt;} 和 \ 之间有一个空格）</p>



<h4>内容三：find 参数<br>3.1 匹配名称的参数</h4>



<p>1) -name n 名称是 n 的文件或目录<br>2) -iname n 名称是 n 的文件或目录，并且忽略大小写<br>3) -lname n 名称是 n 的链接</p>



<p>（注意：在 3) 参数中，n 是被链接文件的名称而不是链接文件本身的名称）</p>



<h4>3.2 匹配属性的参</h4>



<p>-type n :文件类型是 n 的文件</p>



<p>（补充：这里的 n 可以是 d、f、l，它们分别代表目录、文件、链接）</p>



<h4>3.3 匹配所有者的参数</h4>



<p>1) -uid n 所属 gid 是 n 的文件或目录<br>2) -user n 所属主名称为 n 的文件或目录<br>3) -gid n 所属 gid 是 n 的文件或目录<br>4) -group n 所属组名称为 n 的文件或目录<br>5) -nouser 匹配无所属主的文件或目录<br>6) -nogroup 匹配无所属组的文件或目录</p>



<h4>3.4 匹配权限的参数</h4>



<p>1) -perm /u=n 所属主权限是 n 的文件或目录<br>2) -perm /u=n 所属组权限是 n 的文件或目录<br>3) -perm /o=n 所其他的权限是 n 的文件或目录</p>



<p>（补充：在以上 1) 到 3) 参数中 n 可以是 r、w、x 它们分别代表读权限、写权限、执行权限）</p>



<p>4) -perm -n 所属主、所属组、其他的权限是 n 的文件或目录</p>



<p>（补充：在 (4 参数中 n 是可以是 1、2、4）</p>



<p>5) -perm nnn 权限是 nnn 的文件或目录</p>



<p>（<br>补充：<br>在 5) 参数中：<br>n 是数字<br>第一个 n 是特殊权限<br>第二个 n 是所属主的权限<br>第三个 n 是所属组的权限<br>第四个 n 是其他的权限<br>例：600<br>）</p>



<p>6) -perm nnnn 权限是 nnnn 的文件或目录</p>



<p>（<br>补充：<br>在 6) 参数中：<br>n 是数字<br>第一个 n 是特殊权限<br>第二个 n 是所属主的权限<br>第三个 n 是所属组的权限<br>第四个 n 是其他的权限<br>例：0600<br>）</p>



<h4>3.5 匹配时间的参数</h4>



<p>1) -amin n 在过去 n 分钟内被读取过的文件或目录<br>2) -anewer file 比文件 file 更晚被读取过的文件或目录<br>3) -atime n 在过去 n 天内被读取过的文件或目录<br>4) -mmin n 在过去 n 分钟内被修改过内容的文件或目录<br>5) -mnewer file 比文件 file 更晚被修改过内容的文件或目录<br>6) -mtime n 在过去 n 天内被修改过内容的文件或目录<br>7) -cmin n 在过去 n 分钟内被修改过属性（比如新建）的文件或目录<br>8) -cnewer file 比文件 file 更晚被修改过属性（比如新建）的文件或目录<br>9) -ctime n 在过去 n 天内被修改过属性（比如新建）的文件或目录</p>



<p>（补充：在以上 1) 到 9) 参数中 n 是数字， +n 表示 n 以前，-n 表示 n 以内，n 表示第 n）</p>



<h4>3.6 匹配大小的参数</h4>



<p>1) -empty 为空的文件或目录<br>2) -size n 文件大小是 n 的文件或目录</p>



<p>（补充：在 2) 参数中 n 是数字， +n 表示比 n 大，-n 表示比 n 小，单位有 b、m、g 等）</p>



<h4>3.7 匹配目录的参数</h4>



<p>1) -path &#8216;n&#8217; 路径名称符合 n 的文件或目录<br>2) -ipath &#8216;n&#8217; 路径名称符合 n 的文件或目录，并且忽略大小写<br>3) -depth n 路径深度为 n 的文件或目录<br>4) -maxdepth n 最大路劲深度为 n 的文件或目录</p>



<p>（补充：在以上 1) 到 4) 参数中 n 是数字）</p>



<h4>3.8 匹配格式化方式的参数</h4>



<p>1) -fstype n 匹配硬盘格式为 n 文件或目录</p>



<p>（补充：1) 参数中 n 可以是 ext3、ext4、xfs 等硬盘格式）</p>



<p>2) -mount 是被挂载的文件或目录</p>



<h4>3.9 逻辑匹配参数</h4>



<p>1) -not 不匹配后面的参数，需要放在其他参数前面<br>2) ! 不匹配后面的参数，需要放在其他参数前面<br>3) -a 和，需要放在两个参数之前<br>4) -and 和，需要放在两个参数之前<br>5) -o 或，需要放在两个参数之前<br>6) -or 或，需要放在两个参数之前<br>7) &lt;参数> ( &lt;参数> n &lt;参数> ) 指定将某两个参数作为一个整体和另一个逻辑参数进行匹配<br>8) &lt;参数> -prune -n &lt;参数> &lt;参数> 指定某两个参数进行逻辑匹配</p>



<p>（补充：在以上 7)  到 8) 参数中 n 可以是 -a、-and、-o、-or 以上 3) 到 6) 参数）</p>



<h4>内容四：find 的使用案例<br>4.1 案例一：匹配名称的参数</h4>



<p>从当前目录开始查找以 txt 结尾的文件和目录</p>



<pre class="wp-block-code"><code># find . -name "*\.txt"</code></pre>



<h4>4.2 案例二：匹配属性的参</h4>



<p>从当前目录开始查找目录</p>



<pre class="wp-block-code"><code># find . -type d</code></pre>



<h4>4.3 案例三：匹配所有者的参数<br>4.3.1 从当前目录开始查找所属主是 root 的文件和目录</h4>



<pre class="wp-block-code"><code># find . -user root</code></pre>



<h4>4.3.2 从当前目录开始查找没有所属主和所属组的文件和目录</h4>



<pre class="wp-block-code"><code># find . -nouser -o -nogroup</code></pre>



<h4>4.3.3 查找所有所属主是 natasha 的文件并将它们复制到 /root/findfiles 目录下</h4>



<pre class="wp-block-code"><code># find find / -user natasha -exec cp -rp {} /root/findfiles/ \;</code></pre>



<h4>4.4 案例四：匹配权限的参数<br>4.4.1 从当前目录开始查找所有权限为 0777 的文件，并将其显示出来</h4>



<pre class="wp-block-code"><code># find . -type f -perm 0777 -exec ls -l {}\;</code></pre>



<h4>4.4.2 从当前目录开始查找权限为 222 的文件</h4>



<pre class="wp-block-code"><code># find . -type f -perm -2</code></pre>



<h4>4.4.3 从当前目录开始查找有任何执行权限的文件和目录</h4>



<pre class="wp-block-code"><code># find . -perm /a=x</code></pre>



<h4>4.4.4 查找所有包含特殊权限的文件和目录</h4>



<pre class="wp-block-code"><code># find / -type f \( -perm -1000 -o -perm -2000 -o -perm -4000 \) -print</code></pre>



<h4>4.5 案例五：匹配时间的参数<br>4.5.1 从当前目录开始查找 10 天内被修改过的文件</h4>



<pre class="wp-block-code"><code># find . -ctime -10</code></pre>



<h4>4.5.2 从 /var/log/mysql 目录开始查找在过去 3 天被修过的文件和目录，并在确认后将其删除</h4>



<pre class="wp-block-code"><code># find /var/log/mysql -type f -mtime +3 -ok rm {}\;</code></pre>



<h4>4.6 案例六：匹配大小的参数<br>4.6.1 从当前目录开始查找所有大小为 0 的文件，并将其显示出来</h4>



<pre class="wp-block-code"><code># find . -type f -size 0 -exec ls -l {} \;</code></pre>



<h4>4.6.2 从当前目录开始查找所有大小为 0 的文件</h4>



<pre class="wp-block-code"><code># find . -type f -empty</code></pre>



<h4>4.7 案例七：匹配目录的参数</h4>



<p>从 / 目录和 /proc/ 目录开始查找文件格式为 ext3 无所属主或所属组的文件和目录</p>



<pre class="wp-block-code"><code># find / -path '/proc/*' -prune -o -fstype ext3 -nouser -o -nogroup</code></pre>



<h4>4.8 案例八：匹配格式化方式的参数</h4>



<p>从 \ 目录开始查找以</p>



<pre class="wp-block-code"><code># find . -type f</code></pre>



<h4>4.9 案例九：逻辑匹配参数<br>4.9.1 从当前目录开始查找以 “.txt” 结尾和以 “.dox” 结尾的文件</h4>



<pre class="wp-block-code"><code># find . -type f \( -name "*.txt" -or -name "*.dox" \)</code></pre>



<h4>4.9.2 从当前目录开始查找权限不是 777 的文件</h4>



<pre class="wp-block-code"><code># find . -type f ! -perm 777</code></pre>



<h4>4.9.3 从当前目录开始查找权限为 2000 和 4000 的文件，并分析文件属性</h4>



<pre class="wp-block-code"><code># find . -type f \( -perm -2000 -o -perm -4000 \) -exec file {} \;</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 sed （修改和打印文本的行）</title>
		<link>https://eternalcenter-2021-12.github.io/sed/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 27 Nov 2019 08:57:55 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Languages (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Basic (基础)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=6862</guid>

					<description><![CDATA[内容目录： 内容一：sed 格式 内容二：sed 选项 内容三：sed 的参数 内容四：sed 的使用案例4.1 案例一：使用 p 参数打印某一行数据4.1.1 在 test.txt 文本里打印第二行的数据4.1.2 在 test.txt 文本里打印第二行到第四行的数据4.1.3 在 test.txt 文本里打印最后一行的数据4.1.4 在 test.txt 文本里打印包含 eternalcenter 的数据4.1.5 在 test.txt 文本里打印以 eternalcenter 结尾的数据4.1.6 在 test.txt 文本里输出总行数4.1.7 在 test.txt 文本里输出奇数行4.1.8 在 test.txt 文本里输出偶数行4.2 案例二：使用 a 参数在某一行下面追加一行数据4.2.1 在 test.txt 文本里在第二行下面追加一行 eternalcenter4.2.2 在 test.txt 文本里在 abc 那一行下面添加一行 eternalcenter4.2.3 在 test.txt &#8230; <p class="link-more"><a href="https://eternalcenter-2021-12.github.io/sed/" class="more-link">Continue reading<span class="screen-reader-text"> "[命令] Linux 命令 sed （修改和打印文本的行）"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2>内容目录：</h2>



<h4>内容一：sed 格式</h4>



<h4>内容二：sed 选项</h4>



<h4>内容三：sed 的参数</h4>



<h4>内容四：sed 的使用案例<br>4.1 案例一：使用 p 参数打印某一行数据<br>4.1.1 在 test.txt 文本里打印第二行的数据<br>4.1.2 在 test.txt 文本里打印第二行到第四行的数据<br>4.1.3 在 test.txt 文本里打印最后一行的数据<br>4.1.4 在 test.txt 文本里打印包含 eternalcenter 的数据<br>4.1.5 在 test.txt 文本里打印以 eternalcenter 结尾的数据<br>4.1.6 在 test.txt 文本里输出总行数<br>4.1.7 在 test.txt 文本里输出奇数行<br>4.1.8 在 test.txt 文本里输出偶数行<br>4.2 案例二：使用 a 参数在某一行下面追加一行数据<br>4.2.1 在 test.txt 文本里在第二行下面追加一行 eternalcenter<br>4.2.2 在 test.txt 文本里在 abc 那一行下面添加一行 eternalcenter<br>4.2.3 在 test.txt 文本里在以 a 开头的行下面添加 eternalcenter<br>4.2.4 在 test.txt 文本里在以 [a] 开头的行下面添加 eternalcenter<br>4.2.5 在 test.txt 文本里最后一行下面添加 eternalcenter<br>4.3 案例三：使用 i 参数在某一行上面插入一行数据<br>4.3.1 在 test.txt 文本里在第二行上面插入一行 eternalcenter<br>4.3.2 在 test.txt 文本里在 abc 那一行上面添加一行 eternalcenter<br>4.3.3 在 test.txt 文本里在以 a 开头的行上面添加 eternalcenter<br>4.3.4 在 test.txt 文本里在以 [a] 开头的行上面添加 eternalcenter<br>4.3.5 在 test.txt 文本里最后一行上面添加 eternalcenter<br>4.4 案例四：使用 c 参数替换某一行数据<br>4.4.1 在 test.txt 文本里将第二行替换成 eternalcenter<br>4.4.2 在 test.txt 文本里将 abc 那一行替换成 eternalcenter<br>4.4.3 在 test.txt 文本里将以 a 开头的那一行替换成 eternalcenter<br>4.4.4 在 test.txt 文本里将以 [a] 开头的那一行替换成 eternalcenter<br>4.4.5 在 test.txt 文本里将以 eternalcentre 开头的那一行替换成 eternalcenter ALL=(ALL) NOPASSWD: ALL<br>4.5 案例五：使用 d 参数删除某一行<br>4.5.1 在 test.txt 文本里删除第二行<br>4.5.2 在 test.txt 文本里删除包含 abc 的那一行<br>4.5.3 在 test.txt 文本里删除以 a 开头的那一行<br>4.5.4 在 test.txt 文本里删除以 [a] 开头的那一行<br>4.5.5 在 test.txt 文本里删除第二行到第四行<br>4.6 案例六：使用 s 参数替换某一行某些数据<br>4.6.1 在 test.txt 文本里将所有行的第一个 eternalcentre 换成 eternalcenter<br>4.6.2 在 test.txt 文本里将所有行的所有 eternalcentre 换成 eternalcenter<br>4.6.3 在 test.txt 文本里将包含 eternalcentre 的行换成 eternalcenter<br>4.6.4 在 test.txt 文本里将第三行的第二个 eternalcentre 换成 eternalcenter<br>4.6.5 在 test.txt 文本里在所有行前面添加 eternalcenter<br>4.6.6 在 test.txt 文本里将第二行替换成 eternalcenter<br>4.6.7 在 test.txt 文本里将最后一行替换成 eternalcenter<br>4.6.8 在 test.txt 文中里将第二到第三行替换成 eternalcenter<br>4.6.9 在 test.txt 文本里将 eternalcenter 前面的数据和后面的数据对调位置<br>4.6.10 在 test.txt 文本里删除每行的第一个字符和最后一个字符<br>4.6.11 在 test.txt 文本里删除每行的第二个字符和最后一个字符<br>4.6.12 在 test.txt 文本里删除所有的数字和空格<br>4.6.13 在 test.txt 文本里将所有的大写字母都添加括号<br>4.6.14 在 test.txt 文本里给第七行和第九行前面添加 “#”<br>4.6.15 在 test.txt 文本里删除第一个空格<br>4.7 案例七：使用 h、H、g、G 参数复制和粘贴<br>4.7.1 sed 命令的工作原理<br>4.7.2 h、H、g、G、d、D 参数的讲解<br>4.7.2.1 h、H、g、G、d、D 参数的作用简介<br>4.7.2.2 h、H、g、G、d、D 的功能示意图<br>4.7.3 h、H、g、G、d、D 的使用案例<br>4.7.3.1 将第一行的数据添加到第三行后面<br>4.7.3.2 将第一行的数据替换第三行<br>4.7.3.3 将第一行和第二行的数据添加到第三行后面<br>4.7.3.4 将第一行和第二行的数据替换第三行<br>4.7.3.5 将第一个以 a 开头的行的数据添加到第三行后面<br>4.7.3.6 将第一个和第二个以 a 开头的行的数据添加到第三行后面<br>4.8 案例八：sed 一次匹配多个参数</h4>



<h2>具体的内容：</h2>



<h4>内容一：sed 格式</h4>



<pre class="wp-block-code"><code># sed &lt;option&gt; &lt;parameter&gt; &lt;file&gt;</code></pre>



<h4>内容二：sed 选项</h4>



<p>1) -n 或 &#8211;quiet 或 &#8211;silent 仅显示处理后的内容，没处理的内容就不显示了<br>2) -i 实现数据的变更<br>3) -e &lt;脚本> 或 &#8211;expression=&lt;脚本> 以指定的脚本来处理输入的文本<br>4) -r 支持扩展正则<br>5) -f &lt;脚本文件> 或 &#8211;file=&lt;脚本文件> 以指定的脚本文件来处理输入的文本<br>6) -h 或 &#8211;help 显示帮助内容<br>7) -V 或 &#8211;version 显示版本信息</p>



<h4>内容三：sed 的参数</h4>



<p>1) p 打印某一行的数据<br>2) a 在某一行下面追加一行的数据<br>3) i 在某一行上面插入一行的数据<br>4) c 替换某一行的数据<br>5) d 删除某一行<br>6) s 替换某一行的某些数据<br>7) h、H、g、G 复制和粘贴某些行的数据</p>



<h4>内容四：sed 的使用案例<br>4.1 案例一：使用 p 参数打印某一行数据<br>4.1.1 在 test.txt 文本里打印第二行的数据</h4>



<pre class="wp-block-code"><code># sed -n 2p test.txt</code></pre>



<h4>4.1.2 在 test.txt 文本里打印第二行到第四行的数据</h4>



<pre class="wp-block-code"><code># sed -n 2,4p test.txt</code></pre>



<h4>4.1.3 在 test.txt 文本里打印最后一行的数据</h4>



<pre class="wp-block-code"><code># sed -n '$p' test.txt</code></pre>



<h4>4.1.4 在 test.txt 文本里打印包含 eternalcenter 的数据</h4>



<pre class="wp-block-code"><code># sed -n '/eternalcenter/p' test.txt</code></pre>



<h4>4.1.5 在 test.txt 文本里打印以 eternalcenter 结尾的数据</h4>



<pre class="wp-block-code"><code># sed -n '/eternalcenter$/p' test.txt</code></pre>



<h4>4.1.6 在 test.txt 文本里输出总行数</h4>



<pre class="wp-block-code"><code># sed -n $= test.txt</code></pre>



<h4>4.1.7 在 test.txt 文本里输出奇数行</h4>



<pre class="wp-block-code"><code># sed -n 'p;n' test.txt</code></pre>



<h4>4.1.8 在 test.txt 文本里输出偶数行</h4>



<pre class="wp-block-code"><code># sed -n 'n;p' test.txt</code></pre>



<h4>4.2 案例二：使用 a 参数在某一行下面追加一行数据<br>4.2.1 在 test.txt 文本里在第二行下面追加一行 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "2a eternalcenter" test.txt</code></pre>



<h4>4.2.2 在 test.txt 文本里在 abc 那一行下面添加一行 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/abc/a eternalcenter" test.txt</code></pre>



<h4>4.2.3 在 test.txt 文本里在以 a 开头的行下面添加 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/^a/a eternalcenter" test.txt</code></pre>



<h4>4.2.4 在 test.txt 文本里在以 [a] 开头的行下面添加 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/^\&#91;a\]/a eternalcenter" test.txt</code></pre>



<h4> 4.2.5 在 test.txt 文本里最后一行下面添加 eternalcenter </h4>



<pre class="wp-block-code"><code># sed "$a eternalcenter" test.txt</code></pre>



<h4>4.3 案例三：使用 i 参数在某一行上面插入一行数据<br>4.3.1 在 test.txt 文本里在第二行上面插入一行 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "2i eternalcenter" test.txt</code></pre>



<h4>4.3.2 在 test.txt 文本里在 abc 那一行上面添加一行 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/abc/i eternalcenter" test.txt</code></pre>



<h4>4.3.3 在 test.txt 文本里在以 a 开头的行上面添加 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/^a/i eternalcenter" test.txt</code></pre>



<h4>4.3.4 在 test.txt 文本里在以 [a] 开头的行上面添加 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/^\&#91;a\]/i eternalcenter" test.txt</code></pre>



<h4> 4.3.5 在 test.txt 文本里最后一行上面添加 eternalcenter  </h4>



<pre class="wp-block-code"><code># sed "$a eternalcenter" test.txt</code></pre>



<h4>4.4 案例四：使用 c 参数替换某一行数据<br>4.4.1 在 test.txt 文本里将第二行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "2c\ eternalcenter" test.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed "2ceternalcenter" test.txt</code></pre>



<h4>4.4.2 在 test.txt 文本里将 abc 那一行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/abc/c\ eternalcenter" test.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed "/abc/ceternalcenter" test.txt</code></pre>



<h4>4.4.3 在 test.txt 文本里将以 a 开头的那一行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/^a/c\ eternalcenter" test.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed "/^a/ceternalcenter" test.txt</code></pre>



<h4>4.4.4 在 test.txt 文本里将以 [a] 开头的那一行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed "/^\&#91;a\]/c\ eternalcenter" test.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed "/^\&#91;a\]/ceternalcenter" test.txt</code></pre>



<h4>4.4.5 在 test.txt 文本里将以 eternalcentre 开头的那一行替换成 eternalcenter ALL=(ALL) NOPASSWD: ALL</h4>



<pre class="wp-block-code"><code># sed "/^eternalcentre/c\ eternalcenter\ ALL=\(ALL\)\ NOPASSWD:\ ALL" test.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed "/^eternalcentre/c\eternalcenter\ ALL=\(ALL\)\ NOPASSWD:\ ALL" test.txt</code></pre>



<h4>4.5 案例五：使用 d 参数删除某一行<br>4.5.1 在 test.txt 文本里删除第二行</h4>



<pre class="wp-block-code"><code># sed 2d test.txt</code></pre>



<h4>4.5.2 在 test.txt 文本里删除包含 abc 的那一行</h4>



<pre class="wp-block-code"><code># sed /"abc"/d test.txt</code></pre>



<h4>4.5.3 在 test.txt 文本里删除以 a 开头的那一行</h4>



<pre class="wp-block-code"><code># sed /"^a"/d test.txt</code></pre>



<h4>4.5.4 在 test.txt 文本里删除以 [a] 开头的那一行</h4>



<pre class="wp-block-code"><code># sed /"^\&#91;a\]"/d test.txt</code></pre>



<h4>4.5.5 在 test.txt 文本里删除第二行到第四行</h4>



<pre class="wp-block-code"><code># sed '2,4d' test.txt</code></pre>



<h4>4.6 案例六：使用 s 参数替换某一行某些数据<br>4.6.1 在 test.txt 文本里将所有行的第一个 eternalcentre 换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed 's/eternalcentre/eternalcneter/' test.txt</code></pre>



<h4>4.6.2 在 test.txt 文本里将所有行的所有 eternalcentre 换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed 's/eternalcentre/eternalcneter/g' test.txt</code></pre>



<h4>4.6.3 在 test.txt 文本里将包含 eternalcentre 的行换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed 's/.*eternalcentre.*/eternalcneter/' test.txt</code></pre>



<h4>4.6.4 在 test.txt 文本里将第三行的第二个 eternalcentre 换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed '3s/eternalcentre/eternalcenter/2' 1.txt</code></pre>



<h4>4.6.5 在 test.txt 文本里在所有行前面添加 eternalcenter</h4>



<pre class="wp-block-code"><code># sed 's/^/eternalcenter/g' test.txt</code></pre>



<h4>4.6.6 在 test.txt 文本里将第二行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed '2s/.*/eternalcenter/' test.txt</code></pre>



<h4>4.6.7 在 test.txt 文本里将最后一行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed '$s/.*/eternalcenter/' test.txt</code></pre>



<h4>4.6.8 在 test.txt 文中里将第二到第三行替换成 eternalcenter</h4>



<pre class="wp-block-code"><code># sed '2,3s/.*/eternalcenter/' test.txt</code></pre>



<h4>4.6.9 在 test.txt 文本里将 eternalcenter 前面的数据和后面的数据对调位置</h4>



<pre class="wp-block-code"><code># sed "s/^\(.*\)\(eternalcenter\)\(.*\)$/\3\2\1/" test.txt</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># sed -r "s/(.*)(eternalcenter)(.*)/\3\2\1/" test.txt</code></pre>



<h4>4.6.10 在 test.txt 文本里删除每行的第一个字符和最后一个字符</h4>



<pre class="wp-block-code"><code># sed 's/.//1;s/.$//' test.txt</code></pre>



<h4>4.6.11 在 test.txt 文本里删除每行的第二个字符和最后一个字符</h4>



<pre class="wp-block-code"><code># sed 's/.//2;s/.$//' test.txt</code></pre>



<h4>4.6.12 在 test.txt 文本里删除所有的数字和空格</h4>



<pre class="wp-block-code"><code># sed -r 's/&#91;0-9]//g;s/^( )+//' test.txt</code></pre>



<h4>4.6.13 在 test.txt 文本里将所有的大写字母都添加括号</h4>



<pre class="wp-block-code"><code># sed 's/&#91;A-Z]/(&amp;)/g' test.txt</code></pre>



<h4>4.6.14 在 test.txt 文本里给第七行和第九行前面添加 &#8220;#&#8221;</h4>



<pre class="wp-block-code"><code># sed '7,9s/^/#/' test.txt</code></pre>



<h4>4.6.15 在 test.txt 文本里删除第一个空格</h4>



<pre class="wp-block-code"><code># sed -r 's/( )(.*)/\2/'</code></pre>



<h4>4.7 案例七：使用 h、H、g、G 参数复制和粘贴<br>4.7.1 sed 命令的工作原理</h4>



<p>1) 从第一行开始一行一行地读取文本里的内容<br>2) 每读取一行就将数据存入到 pattern space 里面<br>3) 在 pattern sapce 中执行 sed 命令<br>4) 再打印 pattern space 中的内容然后将其清空<br>5) 之后重复以上操作再开始读取文本里的下一行<br>6) pattern space 里的数据可以存储到 hold space 里面</p>



<p>（<br>补充：<br>pattern space 相当于处理数据的流水线<br>hold space 相当于暂时存储数据的仓库<br>）</p>



<h4>4.7.2 h、H、g、G、d、D 参数的讲解<br>4.7.2.1 h、H、g、G、d、D 参数的作用简介</h4>



<p>1) g 将 hold space 中的内容拷贝到 pattern space 中，原来 pattern space 里的内容清除<br>2) G 将 hold space 中的内容 append 到 pattern space\n 后<br>3) h 将 pattern space 中的内容拷贝到 hold space 中，原来的 hold space 里的内容被清除<br>4) H 将 pattern space 中的内容 append 到 hold space\n 后<br>5) d 删除 pattern 中的所有行，并读入下一新行到 pattern 中<br>6) D 删除 multiline pattern 中的第一行，不读入下一行</p>



<h4>4.7.2.2 h、H、g、G、d、D 的功能示意图</h4>



<pre class="wp-block-code"><code>P H     P H     P H
1    h  1 1  d    1

P H     P H     P H     P H
2 1  G  2 1  H  2 1  d    1
        1       1 2       2
                  1       1

P H     P H     P H
3 2  G  3 2  h  3 3
  1     2 1     2 2
        1       1 1

P H     P H
3 2  g  2 2
  1     1 1</code></pre>



<p>（<br>注意：<br>1) 这里的 P 指的是 pattern space<br>2) 这里的 H 指的是 hold space<br>）</p>



<p>（<br>补充：<br>h 其实就是清空现在粘贴板里的内容然后重新复制<br>H 其实就是不清空现在粘贴板里的内容然后再再原来粘贴版的内容基础上再追加复制<br>g 其实就是替换粘贴<br>G 其实就是追加粘贴<br>）</p>



<h4>4.7.3 h、H、g、G、d、D 的使用案例<br>4.7.3.1 将第一行的数据添加到第三行后面</h4>



<pre class="wp-block-code"><code># sed -e '1h' -e '3G' test.txt</code></pre>



<h4>4.7.3.2 将第一行的数据替换第三行</h4>



<pre class="wp-block-code"><code># sed -e '1h' -e '3g' test.txt</code></pre>



<h4>4.7.3.3 将第一行和第二行的数据添加到第三行后面</h4>



<pre class="wp-block-code"><code># sed -e '1h' -e '2H' -e '3G' test.txt</code></pre>



<h4>4.7.3.4 将第一行和第二行的数据替换第三行</h4>



<pre class="wp-block-code"><code># sed -e '1h' -e '2H' -e '3g' test.txt</code></pre>



<h4>4.7.3.5 将第一个以 a 开头的行的数据添加到第三行后面</h4>



<pre class="wp-block-code"><code># sed -e '/^a/h' -e '3G' 1.txt</code></pre>



<h4>4.7.3.6 将第一个和第二个以 a 开头的行的数据添加到第三行后面</h4>



<pre class="wp-block-code"><code># sed -e '/^a/h' -e'/^a/H' -e '3G' 1.txt</code></pre>



<h4>4.8 案例八：sed 一次匹配多个参数</h4>



<p>分别在 test.txt 文本里在 abc 和 bbb 那两行下面添加一行 eternalcenter</p>



<pre class="wp-block-code"><code># sed -e "/abc/a eternalcenter" -e "/^bbb/a eternalcenter" test.txt</code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>[命令] Linux 命令 grep （打印文本的行）</title>
		<link>https://eternalcenter-2021-12.github.io/grep/</link>
		
		<dc:creator><![CDATA[Mingyu Zhu]]></dc:creator>
		<pubDate>Wed, 27 Nov 2019 07:18:17 +0000</pubDate>
				<category><![CDATA[Chinese (中文)]]></category>
		<category><![CDATA[Languages (语言)]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Basic (基础)]]></category>
		<category><![CDATA[System (系统)]]></category>
		<category><![CDATA[System File (系统文件)]]></category>
		<category><![CDATA[System File Security (系统文件安全)]]></category>
		<category><![CDATA[System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志)]]></category>
		<category><![CDATA[System Security (系统安全)]]></category>
		<category><![CDATA[System Storage & System Directory & System File (系统存储 & 系统目录 & 系统文件)]]></category>
		<guid isPermaLink="false">https://eternalcenter-2021-12.github.io/?p=6858</guid>

					<description><![CDATA[案例一：grep 使用正则表达式匹配 或者： 案例二：grep 显示行号2.1 grep 显示某些关键字所在行行号 2.2 grep 显示哪些行号是空行 案例三：grep 取反匹配3.1 grep 取反不匹配某些关键字 3.2 grep 取反不显示空行 案例四：grep 完全匹配 案例五：grep 匹配区分大小写 案例六：grep 统计匹配成功次数 案例七：grep 将匹配成功的部分自动添加颜色 案例八：grep 将匹配成功的部分自动取消颜色 案例九：grep 一次匹配多个参数]]></description>
										<content:encoded><![CDATA[
<h4>案例一：grep 使用正则表达式匹配</h4>



<pre class="wp-block-code"><code># grep -E '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
IPADDR=192.168.8.31
GATEWAY=192.168.8.55</code></pre>



<p>或者：</p>



<pre class="wp-block-code"><code># egrep '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
IPADDR=192.168.8.31
GATEWAY=192.168.8.55</code></pre>



<h4>案例二：grep 显示行号<br>2.1 grep 显示某些关键字所在行行号</h4>



<pre class="wp-block-code"><code># egrep -n '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
16:IPADDR=192.168.8.31
18:GATEWAY=192.168.8.55</code></pre>



<h4>2.2 grep 显示哪些行号是空行</h4>



<pre class="wp-block-code"><code># egrep -n ^$ /etc/resolv.conf</code></pre>



<h4>案例三：grep 取反匹配<br>3.1 grep 取反不匹配某些关键字</h4>



<pre class="wp-block-code"><code># egrep -v '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens192
UUID=5cda4d03-45c9-4856-80a6-f0bd0962d871
DEVICE=ens192
ONBOOT=yes
NETMASK=255.255.255.0
ZONE=public</code></pre>



<h4>3.2 grep 取反不显示空行</h4>



<pre class="wp-block-code"><code># egrep -v ^$ /etc/resolve.conf
### /etc/resolv.conf is a symlink to /var/run/netconfig/resolv.conf
### autogenerated by netconfig!
#
# Before you change this file manually, consider to define the
# static DNS configuration using the following variables in the
# /etc/sysconfig/network/config file:
#     NETCONFIG_DNS_STATIC_SEARCHLIST
#     NETCONFIG_DNS_STATIC_SERVERS
#     NETCONFIG_DNS_FORWARDER
# or disable DNS configuration updates via netconfig by setting:
#     NETCONFIG_DNS_POLICY=''
#
# See also the netconfig(8) manual page and other documentation.
#
### Call "netconfig update -f" to force adjusting of /etc/resolv.conf.
nameserver 192.168.0.1</code></pre>



<h4>案例四：grep 完全匹配</h4>



<pre class="wp-block-code"><code># egrep -o '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
192.168.8.31
192.168.8.55</code></pre>



<h4>案例五：grep 匹配区分大小写</h4>



<pre class="wp-block-code"><code># egrep -i '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
IPADDR=192.168.8.31
GATEWAY=192.168.8.55</code></pre>



<h4>案例六：grep 统计匹配成功次数</h4>



<pre class="wp-block-code"><code># egrep -c '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
2</code></pre>



<h4>案例七：grep 将匹配成功的部分自动添加颜色</h4>



<pre class="wp-block-code"><code># egrep --color=auto '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192
IPADDR=192.168.8.31
GATEWAY=192.168.8.55</code></pre>



<h4>案例八：grep 将匹配成功的部分自动取消颜色</h4>



<pre class="wp-block-code"><code># egrep --color=no '(&#91;1-9]&#91;0-9]{0,2}\.){3}&#91;1-9]&#91;0-9]{0,2}' /etc/sysconfig/network-scripts/ifcfg-ens192  
IPADDR=192.168.8.31
GATEWAY=192.168.8.55</code></pre>



<h4>案例九：grep 一次匹配多个参数</h4>



<pre class="wp-block-code"><code># grep -e root -e zhumingyu /etc/passwd
root:x:0:0:root:/root:/bin/bash
zhumingyu:x:1001:1001:root:/root:/bin/bash</code></pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
