深入解析:麒麟操作系统 | 常用命令及脚本(2)
<style>pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; line-height: 1.6 !important; padding: 16px !important; margin: 16px 0 !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; tab-size: 4 !important; -moz-tab-size: 4 !important; max-width: 100% !important; box-sizing: border-box !important }code { font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow-wrap: normal !important; display: inline !important; background: rgba(0, 0, 0, 0) !important; border: none !important; padding: 0 !important; margin: 0 !important; line-height: inherit !important }
pre code { background: rgba(0, 0, 0, 0) !important; border: 0 !important; border-radius: 0 !important; display: block !important; line-height: 1.6 !important; margin: 0 !important; max-width: none !important; overflow: visible !important; padding: 0 !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; color: inherit !important }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: rgba(112, 128, 144, 1) !important; font-style: italic !important }
.token.punctuation { color: rgba(153, 153, 153, 1) !important }
.token.atrule, .token.attr-value, .token.keyword { color: rgba(0, 119, 170, 1) !important; font-weight: bold !important }
.token.function, .token.class-name { color: rgba(221, 74, 104, 1) !important; font-weight: bold !important }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: rgba(102, 153, 0, 1) !important }
.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted { color: rgba(153, 0, 85, 1) !important }
.cnblogs-markdown pre, .cnblogs-post-body pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; padding: 16px !important; margin: 16px 0 !important }
pre, pre, pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important }</style>
<style>pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; line-height: 1.6 !important; padding: 16px !important; margin: 16px 0 !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; tab-size: 4 !important; -moz-tab-size: 4 !important; max-width: 100% !important; box-sizing: border-box !important }
code { font-family: "Consolas", "Monaco", "Courier New", monospace !important; font-size: 14px !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow-wrap: normal !important; display: inline !important; background: rgba(0, 0, 0, 0) !important; border: none !important; padding: 0 !important; margin: 0 !important; line-height: inherit !important }
pre code { background: rgba(0, 0, 0, 0) !important; border: 0 !important; border-radius: 0 !important; display: block !important; line-height: 1.6 !important; margin: 0 !important; max-width: none !important; overflow: visible !important; padding: 0 !important; white-space: pre !important; word-wrap: normal !important; word-break: normal !important; color: inherit !important }
.token.comment, .token.prolog, .token.doctype, .token.cdata { color: rgba(112, 128, 144, 1) !important; font-style: italic !important }
.token.punctuation { color: rgba(153, 153, 153, 1) !important }
.token.atrule, .token.attr-value, .token.keyword { color: rgba(0, 119, 170, 1) !important; font-weight: bold !important }
.token.function, .token.class-name { color: rgba(221, 74, 104, 1) !important; font-weight: bold !important }
.token.selector, .token.attr-name, .token.string, .token.char, .token.builtin, .token.inserted { color: rgba(102, 153, 0, 1) !important }
.token.property, .token.tag, .token.boolean, .token.number, .token.constant, .token.symbol, .token.deleted { color: rgba(153, 0, 85, 1) !important }
.cnblogs-markdown pre, .cnblogs-post-body pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; background-color: rgba(248, 248, 248, 1) !important; border: 1px solid rgba(225, 228, 232, 1) !important; border-radius: 6px !important; padding: 16px !important; margin: 16px 0 !important }
pre, pre, pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important }</style><div class="htmledit_views atom-one-dark" id="content_views"><p></p><p>先来回顾麒麟往期内容:</p><ul><li><p>麒麟操作系统安装流程(附安装包下载)</p></li><li><p>麒麟系统安装后初始化配置指南</p></li><li><p>麒麟操作系统 | shell 和终端、环境变量</p></li><li><p>麒麟操作系统 | 常用命令及脚本(1)</p></li></ul><hr><h2><img alt="" height="423" src="https://i-blog.csdnimg.cn/direct/f15c8910a16842fa9141d0a97f22f2a7.png" width="979"></h2><p></p><p></p><p class="img-center"><img alt="图片" height="383" src="https://i-blog.csdnimg.cn/img_convert/6b258a5efb53e7270673e7c5114389c2.png" width="900"></p><p><strong>麒麟</strong></p><ul><li><p><strong><strong>本章学习目标</strong></strong></p><p>掌握使用命令的正确方法</p><p></p></li></ul><p></p><p class="img-center"><img alt="图片" height="40" src="https://i-blog.csdnimg.cn/img_convert/7266511bdd7d99cfff7d29e463735e3b.png" width="72"></p><p></p><p class="img-center"><img alt="图片" height="618" src="https://i-blog.csdnimg.cn/img_convert/0905db440f2076b60955db8bfc0ff9ee.png" width="1080"></p><p></p><h2></h2><h2>whoami 命令</h2><p>输出当前使用者的登陆帐号</p><p>whoami 是 用于快速查询<strong>当前有效登录用户账号</strong>的基础命令,功能简洁但高频实用,尤其在多用户切换场景(如 <code>su</code>/<code>sudo</code> 后)中,可快速确认当前操作的用户身份。</p><p></p><p>语法结构</p><p>语法极简,无复杂选项,基本格式为:</p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code>whoami</code></pre>
<p>(注意:命令全小写,无空格,与 <code>who am i</code> 命令功能不同,后者会显示更详细的登录信息,而非仅用户名)</p><p></p><p>实用示例</p><p>在终端直接执行 <code>whoami</code>,即可返回当前用户账号:</p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code># 示例1:当前以普通用户 "user" 登录</code></pre>
<p></p><p></p><p class="img-center"><img alt="图片" height="624" src="https://i-blog.csdnimg.cn/img_convert/fba47986c1a0af0cc20d49c9ab175bc2.png" width="1080"></p><p></p><h2>id 命令 </h2><p>查询用户的身份标识信息</p><p><code>id</code> 命令用于获取指定用户(或当前用户)的<strong>用户 ID(UID)、组 ID(GID)、所属主组及附加组</strong>等核心身份信息,是确认用户权限归属的关键工具(Linux 系统通过 UID/GID 识别用户和组,而非单纯依赖用户名)。</p><h4>语法结构</h4>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code>id[选项][用户名]</code></pre>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code>(若不指定 “用户名”,则默认查询当前用户;选项可选,用于调整输出格式)</code></pre>
<p></p><p>打印用户信息</p><p></p><p class="img-center"><img alt="图片" height="167" src="https://i-blog.csdnimg.cn/img_convert/71180aca00806ae6a60efc220c5b3f31.png" width="1080"></p><p></p><p></p><p class="img-center"><img alt="图片" height="610" src="https://i-blog.csdnimg.cn/img_convert/99da9c256c4f53e466123c23a23e6566.png" width="1080"></p><p></p><h2>who 命令</h2><p>查看系统当前登录用户信息</p><p>who 是用于监控当前所有登入用户状态的核心命令,能直观展示 “谁在使用系统”“通过什么方式登录”“何时登录” 等关键信息,是系统管理员排查用户会话、维护系统安全的常用工具。</p><p></p><p>语法结构</p>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code>who[选项][文件]</code></pre>
<p></p><h2></h2><p></p><p class="img-center"><img alt="图片" height="615" src="https://i-blog.csdnimg.cn/img_convert/dc8fd8659f8894ba779f0f8d0f96e010.png" width="1080"></p><p></p><h2></h2><h2>su 命令</h2><p>Linux 系统中切换用户身份的核心工具<br> su 是 "substitute user"(替换用户)或 "switch user"(切换用户)的缩写。系统会提示输入密码,当密码验证成功后,系统将转入新用户身份的系统环境。默认更改为 root 用户。</p><h4>语法结构</h4>
<pre style="white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important"><code>su[选项][目标用户名]</code></pre>
<p></p><p></p><p class="img-center"><img alt="图片" height="624" src="https://i-blog.csdnimg.cn/img_convert/256a41b68c89ba078a50ac344f1a162b.png" width="1080"></p><p></p><h2>sudo 命令</h2><p><strong>Linux 系统的精细化权限管控工具</strong></p><p>sudo(全称为 "super-user do")是 Linux 中让普通用户临时获取超级用户(root)或其他用户权限的核心工具,它通过精细化的权限配置,既解决了 “普通用户需要高权限操作” 的需求,又避免了直接分享 root 密码的安全风险,是系统管理员管理多用户权限的首选工具。</p><p></p><p>语法结构:</p><p>sudo 要运行的程序或命令</p><p>让管理员能够在不告诉用户 root 密码的前提下,授予普通用户某些特定类型的超级权限。Sudo 意思就是 super-user do,让当前用户暂时以超级管理员 root 的身份来执行这条命令;要想以非 root 用户身份来运行命令,必须使用-u 选项来指定用户;否则,sudo 会默认为 root 用户。</p><p></p><p>sudo 命令注意事项</p><p></p><p class="img-center"><img alt="图片" height="619" src="https://i-blog.csdnimg.cn/img_convert/bac05987fe3962dd92feb81b4df315b7.png" width="1080"></p><p></p></div><br><br>
来源:https://www.cnblogs.com/yxysuanfa/p/19100790
頁:
[1]