The Knowledge of Linux-.-Day02

1.重定向
—stdin—CPU—输出
—stdout(显示屏)1
—stderr(显示屏)2
标准输入:键盘 0
标准输出:显示屏 1
标准错误输出:显示屏 2

输入重定向
        <
        eg. tr ‘a-z’ ‘A-Z’
        <hello
        <HELLO

        <<:写入文件
        eg. cat > filename <<EOF         //写入filename文件并当输入EOF时结束写入
        <this is a file
        <EOF

输出重定向
        标准输出重定向: 1>,>
        标准错误重定向: 2>, 2> /dev/null 放入回收站
        全部输出重定向: &>

输出追加重定向
        标准输出追加重定向: 1>>,>>
        标准错误追加重定向: 2>>
        全部输出追加重定向: &>>

将标准错误转化为标准输出: 2 >& 1

练习
1).显示当前时间,显示格式为hh:mm:ss,并保存到文件time.txt文件中;

date +%T > time.txt

2).保存文件/etc/passwd文件中前10行内容到文件/etc/first_ten_user.txt中

head /etc/passed > /etc/first_ten_user.txt

2.管道符
        符号:|
        表示含义:将上一条命令的标准输出作为管道符后面命令的标准输入

练习
1).显示/etc/passwd文件的第15-18行内容;

cat -b /etc/passwd | head -18 | tail -4

2).找出/bin目录中的命令个数;

ls /bin > binfile
wc -l binfile

3).显示/bin目录中文件大小排前10的文件名,并保存到文件/mnt/tenth_size_file.txt;

ls -s /bin | sort -t ” ” -k 1 -n | tail -10 > /mnt/tenth_size_file.txt

sort命令:用于排序
        -n         //纯数字排序
        -t         //指定分隔符
        -k         //根据分隔符选择用哪一列进行排序
        -r         //逆序排序,由大到小

tee:显示输出到屏幕上,并保存到文件中
练习:
显示/bin中文件包含大写字母的文件,保存到bin_upper_file.txt文件中,并统计个数显示到屏幕

ls /bin/*[[:upper:]]* | tee bin_upper_file.txt
wc -l bin_upper_file.txt

3.vim编辑器的使用
一般模式
        复制 yl yw yy y3y
        粘贴 p
        删除 dl dw dd d3d
        撤销 u
        取消撤销 ctrl+r
        剪切 cl cw cc c3c(注意:剪切后进入插入模式,粘贴时需要退出插入模式)
        分屏
                左右分屏 ctrl+w v
                上下分屏 ctrl+w s
                删除分屏 ctrl+w c
                切换分屏 ctrl+w (上下左右)
        到达文件第一行 gg
        到达文件最后一行 G

一般模式进入插入模式
        i         在光标所在位置插入
        I         在光标所在行首插入
        a        在光标的下一个位置插入
        A        在光标所在行行尾插入
        o        在光标所在行的下一行插入一行
        O        在光标所在行的上一行插入一行
        s         删除光标所在字符进行插入
        S         删除光标所在行进行插入

命令模式
        文件设置
                :set nu                 设置行号
                :set nonu             取消行号
                :set cursorline     设置行线标识
                :set mouse           添加鼠标选择
        注意:以上设置均为临时设置,永久生效需要修改vim配置文件/etc/vimrc

关键字搜索
        /关键字
        n         向下搜索关键字
        N         向上搜索关键字

批量修改字符
        :%s/westos/root            //改一处
        :%s/westos/root/g         //改全部
        :16,18s/westos/root/g   //16-18行

批量添加字符
        ctrl+v选中需要操作的字符,按大写i,进入插入模式,写入要插入的内容,最后按Esc退出插入模式即可。

批量删除字符
        ctrl+v选中需要操作的字符,按小写x或者Delete键即可删除选中内容

退出
        :x         保存退出
        :x!         强制保存退出
        :wq         保存退出
        :wq!         强制保存退出
        :q         退出
        :q!         强制退出

vim帮助查找
        vimtutor
        vimtutor -g zh_cn        //中文版

练习
1).root用户身份执行,复制/etc/group文件到/home/student/Desktop;
2).vim编辑该文件,复制前三行,粘贴到第5 行
3).剪贴第5行,粘贴到最后一行;
4).删除倒数第三行;
5).保存该文件并退出;
6).编辑刚才的group文件,显示行号;
7).在3-10行的最开始批量添加root单词;
8).在左右分屏的情况下,将5-10行中的root替换为student。

4.gedit编辑,类似wps的用法
        ctrl+n        新建
        ctrl+s        保存
        ctrl+o        打开
        ctrl+x        剪切
        ctrl+v        粘贴
        ctrl+c        复制
注意:gedit的帮助文档:yelp help:gedit

5.linux中用户与用户组的管理
        linux系统下几乎一切皆文件;
        linux系统中缺省shell为bash。

用户的管理
        用户文件: /etc/passwd         user:passwd:uid:gid:用户说明:用户家目录:shell类型(shell文件在/etc/shells)
        两个命令:

                useradd
                        useradd -u        //user ID of the new account
                        useradd -g        //name or ID of the primary group of the new account
这里写图片描述
                        useradd -c        //GECOS field of the new account用户说明
这里写图片描述
                        useradd -d        //home directory of the new account家目录
这里写图片描述
                        useradd -s        //login shell of the new account (shell类型)
这里写图片描述
                userdel -r username        //remove home directory and mail spool 删除用户及其家目录
                usermod
                        usermod -u         //new UID for the user account
                        usermod -g         //force use GROUP as new primary group
                        usermod -c         //new value of the GECOS field
                        usermod -d         //new home directory for the user account
                        usermod -s         //new login shell for the user account
                        usermod -G         //new list of supplementary GROUPS
                        usermod -aG         //append the user to the supplemental GROUPS mentioned by the -G option without removing him/her from other groups(添加多个组)
这里写图片描述
                        usermod -md         //move contents of the home directory to the new location (use only with -d)
                id
                        id -u         //print only the effective user ID
                        id -g         //print only the effective group ID(实际组)
                        id -G         //print all group IDs(所有组)
                        id -un         //print a name instead of a number
                        id -gn         //print a name instead of a number
                        id -Gn         //print a name instead of a number
这里写图片描述

用户组的管理
        用户组文件: /etc/group         groupname:passwd:gid:组的成员
        两个命令:

                groupadd -g         //use GID for the new group
                groupdel

这里写图片描述
练习
        新建用户redhat,uid=1888,属于用户组rdgroup,用户说明为“redhat User”,并设置密码为redhat,该用户首次登陆需修改密码。
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值