• day3 Linux基础


    1、正文处理命令及tar命令

    1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖)

    cat /etc/passwd /etc/group >1.txt
    2) 将用户信息数据库文件和用户密码数据库文件纵向合并为一个文件/2.txt(追加)

    cat /etc/passwd /etc/shadow >>2.txt
    3) 将/1.txt、/2.txt两个文件打包为/1.tar

    [root@localhost test]# tar -cvf 1.tar 1.txt 2.txt

    4) 使用gzip命令压缩1.txt文件名为1.txt.gz

    [root@localhost test]# gzip 1.txt
    [root@localhost test]# ls
    1.tar 1.txt.gz 2.txt new_pass.txt

    5) 解压缩1.txt.gz

    [root@localhost test]# gunzip 1.txt.gz
    [root@localhost test]# ll 1.txt
    -rw-r--r--. 1 root root 2703 11月 14 18:25 1.txt

    6) 使用bzip2压缩1.txt压缩后文件名为1.txt.bz2

    [root@localhost test]# bzip2 1.txt
    [root@localhost test]# ls
    1.tar 1.txt.bz2 2.txt new_pass.txt

    7) 解压缩1.txt.bz2

    [root@localhost test]# bunzip2 1.txt.bz2

    [root@localhost test]# ls
    1.tar 1.txt 2.txt new_pass.txt

    8) 解包1.tar,解包后文件存放到/tmp目录下

    [root@bogon test]# tar -tvf 1.tar
    -rw-r--r-- root/root 2703 2016-11-14 18:25 1.txt
    -rw-r--r-- root/root 3367 2016-11-14 18:29 2.txt
    [root@bogon test]# ls /tmp
    [root@bogon test]# tar -xf 1.tar -C/tmp
    [root@bogon test]# ls /tmp
    1.txt 2.txt

    9) 使用tar命令打包并且压缩/1.txt、/2.txt,得到的文件名为1.tar.gz

    [root@bogon test]# tar cvzf 1.tar.gz 1.txt 2.txt
    1.txt
    2.txt
    [root@bogon test]# ls
    1.tar 1.tar.gz 1.txt 2.txt new_pass.txt

    10) 解包1.tar.gz,解包后文件存放到/tmp目录下

    [root@bogon test]# ls /tmp
    [root@bogon test]# tar -xf 1.tar.gz -C/tmp
    [root@bogon test]# ls /tmp
    1.txt 2.txt

    2、利用vi编辑器创建和编辑正文文件 

    1) 使用vi编辑器编辑文件/1.txt进入编辑模式写入内容“hello world”

    [root@localhost test]# vi 1.txt

    进入编辑器之后用a、i、o 进入插入模式 输入hello world 然后按ESC 然后按shift :wq退出
    2) 进入命令行模式复制改行内容,在下方粘贴80行

    80yy 80p
    3) 快速移动光标到文件的最后一行

    G
    4) 快速移动光标到当前屏幕的中间一行

    M
    5) 快速移动光标到文件的第五行

    5G
    6) 在下方插入新的一行内容“welcome to beijing”

    按 i、o

    “welcome to bejing”
    7) 删除刚插入的一行

    将光标移动到刚插入的地方,然后dd
    8) 撤销上一步的操作

    U
    9) 进入扩展模式,执行文件的保存退出操作

    按a、i、o 进入扩展模式 ESC 之后按shift : wq!

    3、系统的初始化和服务 

    1) 以root用户登录系统

    进入操作系统选择root 用户登录
    2) 修改grub配置文件,默认以第1个操作系统启动,将默认的读秒修改为10秒

    [root@localhost ~]# vim /etc/grub.conf

    # grub.conf generated by anaconda
    #
    # Note that you do not have to rerun grub after making changes to this file
    # NOTICE: You have a /boot partition. This means that
    # all kernel and initrd paths are relative to /boot/, eg.
    # root (hd0,0)
    # kernel /vmlinuz-version ro root=/dev/sda2
    # initrd /initrd-[generic-]version.img
    #boot=/dev/sda
    default=0
    timeout=10
    splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title CentOS 6 (2.6.32-573.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=UUID=ba886ad4-f0ac-4b09-a232-7e1f9cd98f24 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-573.el6.x86_64.img

    3) 设置grub菜单密文密码“123”

    [root@localhost ~]# grub-md5-crypt
    Password:
    Retype password:
    $1$SgSY2/$H6xOBhokzSH9j.IguVoWo.
    [root@localhost ~]# vim /etc/grub.conf

    #boot=/dev/sda
    default=0
    timeout=10
    splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    $1$SgSY2/$H6xOBhokzSH9j.IguVoWo.
    title CentOS 6 (2.6.32-573.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=UUID=ba886ad4-f0ac-4b09-a232-7e1f9cd98f24 rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD crashkernel=auto LANG=zh_CN.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet

    initrd /initramfs-2.6.32-573.el6.x86_64.img

    4) 修改系统的默认运行级别为3

    [root@localhost ~]# vim /etc/inittab

    id:3:initdefault:

    5) 使用与运行级别有关的命令重启系统

    shutdown -r now
    reboot
    init 6
    Ctrl+Alt+Delete键
    6) 使用单用户模式修改用户的密码为“123”


    7) 使用救援模式删除grub菜单密码

    4、系统监控 

    1) 实时动态监控系统状态

    top
    2) 退出上一步的操作

    q
    3) 开启top进程

    top
    4) 使用ps命令查看top命令的pid并杀死

    [root@bogon ~]# ps aux | grep 'top' |grep -v 'grep'
    root 5 0.0 0.0 0 0 ? S 14:56 0:00 [stopper/0]
    [root@bogon ~]# kill -9 5

    5) 查看pid为2的进程的进程树

    [root@localhost ~]# pstree 2
    6) 打开火狐浏览器

    firefox
    7) 查找名为firefox的进程

    [root@localhost ~]# ps aux|grep firefix
    root 3062 0.0 0.0 103320 864 pts/1 S+ 22:29 0:00 grep firefix

    8) 杀死名为firefox的进程

    [root@localhost ~]# kill -9 3062

     

  • 相关阅读:
    【curl】Linux下命令行curl详解
    【httpwatch】httpwatch对测试的应用
    【岗位知识小记录】
    linux系统修改route路由
    yum无法正常安装,提示如下 There are no enabled repos Run "yum repolist all"
    Ubuntu14.04切换root用户
    【AAA】AAA协议介绍
    各种工具网站
    任职资格:
    推荐一个下载mac应用的良心网站
  • 原文地址:https://www.cnblogs.com/sunkai1993/p/6063640.html
Copyright © 2020-2023  润新知