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. 以JTextPanel为例Swing的鼠标事件详解

    如下界面可以通过该界面研究一下Swing的鼠标事件: 图中用红粗线圈起来的为JtextPanel,该Panel添加了鼠标事件监听器,鼠标事件监听器有三种,分别为MouseWheelListener,M ...

  2. 图解:如何U盘装Win7系统(傻瓜式装机) + 分区步骤图解(用WIN7自带管理工具)

    原地址:http://wenku.baidu.com/link?url=wV2Pfw2IM21u2KmtAcNweSZRwpXRuKAVAS29dS4aWGEpMtFdDlzZvixCgsvBxIm- ...

  3. hdu 3309 Roll The Cube ( bfs )

    Roll The Cube Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. .net设计模式 - 单例模式

    DoNet设计模式实例之单例模式( Singleton Pattern) 一 : 单例模式的简介:(Brief Introduction) 单例模式(Singleton Pattern),保证一个类只 ...

  5. [poj 1127]Jack Straws[线段相交][并查集]

    题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...

  6. AC自动机---个人总结

    比较好的 AC自动机算法详解.. [转]http://www.cppblog.com/mythit/archive/2009/04/21/80633.html 个人总结:[图是盗用的..] ac自动机 ...

  7. unity3D游戏开发十八之NGUI动画

    我们先来看下帧动画,顾名思义,就是一帧帧的图片组成的动画,我们须要用到UISprite Animation组件,它的属性例如以下: Framerate:播放速率,也就是每秒钟播放的帧数 Name Pr ...

  8. 从SAE又回到BAE,感觉好轻松

    [前言] 我这个人总喜欢对同一类东西比較过来比較过去,用过来用过去. 比如曾经选择浏览器,从開始ie,到遨游,世界之窗.qq等等,用了有10款左右的浏览器,每款都用了不短时间, 终于固定在火狐+chr ...

  9. extjs4 分页工具栏pagingtoolbar的每页显示数据combobox下拉框

    var itemsPerPage = 20; var combo; //创建数据源store Ext.define('recordStore', { extend : 'Ext.data.Store' ...

  10. UVA12304 2D Geometry 110 in 1! 计算几何

    计算几何: 堆几何模版就能够了. . .. Description Problem E 2D Geometry 110 in 1! This is a collection of 110 (in bi ...