zoukankan      html  css  js  c++  java
  • RH033读书笔记(5)-Lab 6 Exploring the Bash Shell

    Lab 6 Exploring the Bash Shell

    Sequence 1: Directory and file organization

    1. Log in as user student with the password student.

    2. [student@stationX ~]$ pwd
    /home/student

    3. [student@stationX ~]$ touch {report,memo,graph}_{sep,oct,nov,dec}_{a,b,c}_{1,2,3}

    4. Use the ls command to examine the results of the last command. You should find that it
    created 108 new, empty files

    5. [student@stationX ~]$ mkdir a_reports
    [student@stationX ~]$ mkdir september october november december
    Again, use ls to examine your work.

    6. [student@stationX ~]$ cd a_reports
    [student@stationX a_reports]$ mkdir one two three
    ls

    7. [student@stationX a_reports]$ cd
    [student@stationX ~]$ ls -l *dec_b_?
    [student@stationX ~]$ mv graph_dec_b_1 december/
    [student@stationX ~]$ mv *dec_b_? december/
    [student@stationX ~]$ ls -l december/

    8. [student@stationX ~]$ mv *nov_b_? november/
    [student@stationX ~]$ mv *oct_b_? october/
    [student@stationX ~]$ mv *sep_b_? september/

    9. [student@stationX ~]$ cd a_reports
    [student@stationX a_reports]$ mv ~/*_a_1 one/
    [student@stationX a_reports]$ cd one
    [student@stationX one]$ ls *sep*
    [student@stationX one]$ rm *sep*
    [student@stationX one]$ ls

    10. [student@stationX one]$ pwd
    /home/student/a_reports/one

    [student@stationX one]$ ls /home/student/*a_2*
    [student@stationX one]$ mv /home/student/*a_2* /home/student/a_reports/two/

    [student@stationX one]$ ls ../../*a_3*
    [student@stationX one]$ mv ../../*a_3* ../three/

    11. [student@stationX one]$ cd
    ls

    12. [student@stationX ~]$ mkdir /tmp/archive
    [student@stationX ~]$ cp report*[12] /tmp/archive/
    [student@stationX ~]$ cp -i report_dec* /tmp/archive/
    cp: overwrite `/tmp/archive/report_dec_c_1'? n
    cp: overwrite `/tmp/archive/report_dec_c_2'? n

    13. [student@stationX ~]$ ls *c*
    [student@stationX ~]$ ls -Fd *c*

    14. [student@stationX ~]$ ls *c_[1-3]
    [student@stationX ~]$ rm *c_[1-3]
    [student@stationX ~]$ ls

    Sequence 2: Automating tasks with shell scripts

    1. Consider the command:
    cp -av /etc/sysconfig ~/backups/sysconfig-yyyymmdd

    2. man date
    /format
    date '+%Y%m%d'

    3. [root@stationX ~]# mkdir ~/bin/

    4. Use nano or vi, ~/bin/backupsysconfig.sh
    #!/bin/bash
    # This script creates a backup of /etc/sysconfig
    # into a datestamped subdirectory of ~/backups/

    5. add a line
    cp -av /etc/sysconfig ~/backups/sysconfig-$(date '+%Y%m%d')

    6. Finally, add a line
    echo "Backup of /etc/sysconfig completed at: $(date)"

    7. Save the file.
    #!/bin/bash
    # This script creates a backup of /etc/sysconfig
    # into a datestamped subdirectory of ~/backups/
    cp -av /etc/sysconfig ~/backups/sysconfig-$(date '+%Y%m%d')
    echo "Backup of /etc/sysconfig completed at: $(date)"

    8. remove today's datestamp
    [root@stationX ~]# rm -rf ~/backups/sysconfig-$(date '+%Y%m%d')

    9. [root@stationX ~]# chmod u+x ~/bin/backup-sysconfig.sh

    10. [root@stationX ~]# ~/bin/backup-sysconfig.sh

    11. If you have problems, double-check your script and try using bash -x in your shbang for
    diagnostic output.

  • 相关阅读:
    【动画】看动画轻松理解「Trie树」
    浅析HTTP/2的多路复用
    HTTPS 详解
    PHP写时复制(Copy On Write)
    golang 几种字符串的拼接方式
    正排索引和倒排索引简单介绍
    传值还是传引用
    lvs与nginx区别
    Docker运行操作系统环境(BusyBox&Alpine&Debian/Ubuntu&CentOS/Fedora)
    原创-thanos组件(聚合多个prometheus组件)原理介绍
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3437573.html
Copyright © 2011-2022 走看看