Linux参考笔记 3

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux参考笔记 3相关的知识,希望对你有一定的参考价值。

四、Vim文本编辑器
1. 三种模式
命令模式:文件打开后的默认模式,只能查看文件内容不能修改
输入模式:可以编辑和修改
末行模式:保存退出
2. 切换
命令模式  -->  输入模式      按i键
命令模式  -->  末行模式      按:键
输入模式和末行模式  --> 命令模式  按Esc键
备注:输入模式和末行模式不能直接切换,需要经过命令模式
3. vim filename
如果filename存在则打开这个文件
如果filename不存在则新建这个文件

实验
1. 在 /root/ 目录下新建文件 hello.sh
1)录入内容“Hello World !!!”
2)保存后使用 cat 命令确认文件内容
2. 修改系统文件 /etc/hosts 
1)在末尾增加一行内容“127.0.0.1    www.baidu.com”
2)使用 ping 命令测试到 www.baidu.com 的连通性,观察结果
# ls /root/hello.sh
# vim /root/hello.sh
按i键
输入 Hello World!!!
按esc键
按:
wq!
# ls /root/hello.sh
# cat /root/hello.sh

4.命令模式操作
光标行内调整
^ = Home键   移动光标到行首
$ = End键    移动光标到行尾

光标行间的调整
gg      跳转到文件的第一行
G       跳转到文件的最后一行

复制,粘贴,删除
yy  复制当前行
#yy 复制当前往下#行
p   当前光标下粘贴
delete  删除当前光标所在的单个字符
dd  删除(剪切)当前行
#dd 删除(剪切)当前光标往下到#行

查找
/world  当前光标往下查找world
n   下一个

eg:
[[email protected] ~]# rm -rf /tmp/*
[[email protected] ~]# mkdir /tmp/test01
[[email protected] ~]# cp /etc/mail.rc /tmp/test01/
[[email protected] ~]# ls /tmp/test01/mail.rc    
[[email protected] ~]# vim /tmp/test01/mail.rc

5.末行模式操作
:w  保存
:q  退出
:wq 保存并退出
:wq!    强制保存并退出
:w /root/xxx.file   把当前文件另存为/root/xxx.file
:r /root/xxx.file   把/root/xxx.file文件加载到当前文件中

6.查找替换
:s/old/new      替换当前行第一个old为new
:s/old/new/g        替换当前行所有的old为new
:n,m s/old/new/g    替换第n-m行所有的old为new
:% s/old/new/g      替换文件内所有的old为new
u   撤销

eg:
[[email protected] test01]# ls /etc/passwd /tmp/test01/passwd
[[email protected] test01]# cp /etc/passwd /tmp/test01/
[[email protected] test01]# ls /etc/passwd /tmp/test01/passwd
[[email protected] test01]# vim /tmp/test01/passwd 
在末行模式输入 
    /root  
    :s/root/feige
    u
    :s/root/feige/g
    u
    :1,10s/root/feige/g
    u
    :%s/root/feige/g
    u
    :q!

显示和关闭行号
:set nu|nonu

五、管理用户和组
1.用户管理
a.用户分类
超级用户:管理员账户root uid为0
系统用户:系统服务产生 uid范围 1 ~ 999
普通用户:管理员自己创建的账户,uid范围 1000 ~ 60000
b.创建用户
# id 账户名        验证系统是否存在这个账户
# useradd 账户名       创建账户
c.设置密码
#passwd 账户      设置密码
d.修改账户信息
#usermod        
    -l 新账户 旧账户  修改登录名字
e.删除账户
#userdel 账户  删除账户
    -r     连同家目录一起删除
总结:
当默认创建一个普通用户的时候,会在/home下创建一个同名的文件夹。
这个文件夹就是创建用户的家目录

eg:
[[email protected] ~]# id nvshen
[[email protected] ~]# useradd nvshen
[[email protected] ~]# id nvshen
[[email protected] ~]# passwd nvshen
[[email protected] ~]# id miaodt
[[email protected] ~]# id nvshen
[[email protected] ~]# usermod -l miaodt nvshen
[[email protected] ~]# id miaodt
[[email protected] ~]# id nvshen
[[email protected] ~]# usermod -l nvshen miaodt
[[email protected] ~]# id miaodt
[[email protected] ~]# id nvshen
[[email protected] ~]# userdel nvshen

实验:
1.新建名为 nvshen 的用户账号,将密码设置为 1234567
测试以用户 nvshen 远程登录到本机系统
2.将此用户的家目录迁移到 /opt/nvshen 目录
重新以用户 nvshen 远程登录本机系统,确认当前 pwd 工作目录位置
3.彻底删除名为 nvshen 的用户账号
检查其ID信息,查看提示结果。检查其家目录是否可用
[[email protected] ~]# id nvshen
[[email protected] ~]# useradd nvshen
[[email protected] ~]# id nvshen
[[email protected] ~]# passwd nvshen
[[email protected] ~]# ssh [email protected]
[[email protected] ~]$ pwd
[[email protected] ~]$ whoami 
[[email protected] ~]$ exit
[[email protected] ~]# ls -ld /opt/nvshen
[[email protected] ~]# ls -ld /home/nvshen/
[[email protected] ~]# usermod -d /opt/nvshen nvshen
[[email protected] ~]# ls -ld /opt/nvshen
[[email protected] ~]# mv /home/nvshen/ /opt/
[[email protected] ~]# ls -ld /opt/nvshen
[[email protected] ~]# ssh [email protected]
[[email protected] ~]$ pwd
[[email protected] ~]$ exit
[[email protected] ~]# id nvshen
[[email protected] ~]# ls -ld /opt/nvshen/
[[email protected] ~]# userdel nvshen
[[email protected] ~]# id nvshen
[[email protected] ~]# ls -ld /opt/nvshen/

2.组管理
a.创建组
#groupadd 组名
    -g gid  创建组的时候指定gid
b.给组添加删除成员(用户)
#gpasswd
    -a:添加指定用户为组成员
    -d:从组内删除指定的成员用户
c.删除组
#groupdel

eg:
[[email protected] ~]# id nvshen
[[email protected] ~]# useradd nvshen
[[email protected] ~]# id nvshen
[[email protected] ~]# groupadd -g 600 stugrp
[[email protected] ~]# gpasswd -a nvshen stugrp
[[email protected] ~]# id nvshen
[[email protected] ~]# groupdel stugrp
[[email protected] ~]# id nvshen

以上是关于Linux参考笔记 3的主要内容,如果未能解决你的问题,请参考以下文章

linux中怎么查看mysql数据库版本

Linux参考笔记 3

Android 逆向Linux 文件权限 ( Linux 权限简介 | 系统权限 | 用户权限 | 匿名用户权限 | 读 | 写 | 执行 | 更改组 | 更改用户 | 粘滞 )(代码片段

20179223《Linux内核原理与分析》第十一周学习笔记

[linux][c/c++]代码片段01

Python 3学习笔记