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.

RH033读书笔记(5)-Lab 6 Exploring the Bash Shell的更多相关文章

  1. RH033读书笔记(11)-Lab 12 Configuring the bash Shell

    Sequence 1: Configuring the bash Shell Deliverable: A system with new aliases that clear the screen, ...

  2. RH133读书笔记(10)-Lab 10 Exploring Virtualization

    Lab 10 Exploring Virtualization Goal: To explore the Xen virtualization environment and the creation ...

  3. RH033读书笔记(7)-Lab 8 Introduction to String Processing

    Lab 8 Introduction to String Processing Sequence 1: Exercises in string processing 1. Other than the ...

  4. RH033读书笔记(15)-Lab 16 The Linux Filesystem

    Lab 16 The Linux Filesystem Goal: Develop a better understanding of Linux filesystem essentials incl ...

  5. RH033读书笔记(2)-Lab 3 Getting Help with Commands

    Lab 3 Getting Help with Commands Sequence 1: Using the Help Tools 1. man -f keyword whatis keyword l ...

  6. RH033读书笔记(4)-Lab 5 File Permissions

    Lab 5 File Permissions Sequence 1: Determining File Permissions 1. What is the symbolic representati ...

  7. RH033读书笔记(3)-Lab 4 Browsing the Filesystem

    Lab 4 Browsing the Filesystem Sequence 1: Directory and File Organization 1. Log in as user student ...

  8. RH033读书笔记(6)-Lab 7 Standard I/O and Pipes

    Lab 7 Standard I/O and Pipes 1. [student@stationX ~]$ cat /proc/cpuinfo /proc/meminfo 2. [student@st ...

  9. RH033读书笔记(8)-Lab 9 Using vim

    Lab 9 Using vim Sequence 1: Navigating with vim 1. Log in as user student 2. [student@stationX ~]$ c ...

随机推荐

  1. hadoop集群空间使用情况报告脚本

    近期集群空间有点紧张,总是操心空间不足而崩溃,近期扩容又不太现实,经与集群用户沟通发现:集群上存储了非常多没用的历史数据,能够删除,这样就能够通过一个crontab脚本每天生成集群空间使用报告,当使用 ...

  2. C#之自己定义的implicit和explicit转换

    在类型转换时常会遇到隐式转换和显式转换.那我们自己定义的类型要怎样去定义隐式转换和显式转换?我们来看一段代码 public class Rational { private Int32 _inner_ ...

  3. SICP 解题集 — SICP 解题集

    SICP 解题集 — SICP 解题集 SICP 解题集¶ 这个文档的目标是成为中文化的.完整的<计算机程序的构造和解释>一书的解题集. 这个解题集的特色是: 对于每道习题,除了习题答案之 ...

  4. POI数据下载器

    偶尔用点儿POI数据,所以写了一个下载器.用到的东西还真不少. 功能点 +编写翻页脚本 +CSharp与JS交互 +POI数据转换json +CSharp的json序列化类 +CSharp读写json ...

  5. H3C低端交换机MAC绑定

    1.MAC地址和端口的绑定<h3c>system[h3c]interface e0/1[h3c-interface]mac-address max-count #关闭交换机端口的MAC学习 ...

  6. SSM框架整合( Spring 、 SpringMVC 和 Mybatis )

    1.基本概念 1.1.Spring Spring 是一个开源框架, Spring 是于 2003  年兴起的一个轻量级的 Java  开发框架,由 Rod Johnson  在其著作 Expert O ...

  7. 通过Java字节码发现有趣的内幕之String篇(上)(转)

    原文出处: jaffa 很多时候我们在编写Java代码时,判断和猜测代码问题时主要是通过运行结果来得到答案,本博文主要是想通过Java字节码的方式来进一步求证我们已知的东西.这里没有对Java字节码知 ...

  8. html5载入JS引用

    直接上代码 w文件 <?xml version="1.0" encoding="UTF-8"? > <div xmlns="http ...

  9. 【甘道夫】Win7x64环境下编译Apache Hadoop2.2.0的Eclipse小工具

    目标: 编译Apache Hadoop2.2.0在win7x64环境下的Eclipse插件 环境: win7x64家庭普通版 eclipse-jee-kepler-SR1-win32-x86_64.z ...

  10. WPF换肤之五:创建漂亮的窗体

    原文:WPF换肤之五:创建漂亮的窗体 换肤效果 经过了前面四章的讲解,我们终于知道了如何拖拉窗体使之改变大小,也知道了如何处理鼠标事件,同时,也知道了如何利用更好的编写方式来编写一个方便实用和维护的换 ...