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.

  • 相关阅读:
    Python 类中方法的内部变量,命名加'self.'变成 self.xxx 和不加直接 xxx 的区别
    用foreach遍历 datagridView 指定列所有的内容
    treeView1.SelectedNode.Level
    YES NO 上一个 下一个
    正则 单词全字匹配查找 reg 边界查找 精确匹配 只匹配字符 不含连续的字符
    抓取2个字符串中间的字符串
    sqlite 60000行 插入到数据库只用不到2秒
    将多行文本以单行的格式保存起来 读和写 ini
    将秒转换成时间格式
    richtextbox Ctrl+V只粘贴纯文本格式
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3437573.html
Copyright © 2011-2022 走看看