作業   1--4

<<<第一單元練習>>>

2.右鍵後選擇open in terminal 可以打開一個bash
3.輸入命令passwd studen然後鍵入密碼倆次就可以修改密碼
4.使用date命令可以顯示當前系統時間
    [root@foundation98 Desktop]# date
    Wed Oct  5 09:19:35 CST 2016
5.顯示時間使用date命令:
    [root@foundation98 Desktop]# date +%H:%M:%S' '%p
    09:26:14 AM
6.使用file命令:
    [root@foundation98 Desktop]# file /usr/bin/clean-binary-files
    /usr/bin/clean-binary-files: POSIX shell script, ASCII text executable
    顯示該文件爲可執行的ascii碼文件
7.該文件由13220個字節組成    
    [root@foundation98 Desktop]# wc -c /usr/bin/clean-binary-files
    13220 /usr/bin/clean-binary-files
8.按上下鍵可以調用最近使用的命令
9.使用ctrl+r+關鍵字可以執行最近一條含有這個字母的命令
#####end######

<<<第二單元練習>>>
1.用命令和正則表達式按照要求建立文件
*)用一條命令建立12個文件WESTOS_classX_linuxY(X的數值範圍爲1-2,Y的數值範圍爲1-6)
*)這些文件都包含在root用戶桌面的study目錄中
*)用一條命令建立8個文件redhat_versionX(x的範圍爲1-8)
*)redhat_virsionX這些文件都包含在/mnt目錄中的VERSION中

    [root@foundation98 Desktop]# mkdir /root/Desktop/study
    [root@fundation98 Desktop]# mkdir /mnt/VERSION
    [root@foundation98 Desktop]# touch /root/Desktop/study  /WESTOS_class{1..2}_linux{1..6}    
    [root@foundation98 Desktop]# touch /mnt/VERSION/redhat_version{1..8}  ##創建文件 以及所需的目錄
    [root@foundation98 Desktop]# ls /root/Desktop/study/ /mnt/VERSION/
    /mnt/VERSION/:
    redhat_version1  redhat_version2  redhat_version3  redhat_version4  redhat_version5          redhat_version6  redhat_version7  redhat_version8

/root/Desktop/study/:
WESTOS_class1_linux1  WESTOS_class1_linux3  WESTOS_class1_linux5  WESTOS_class2_linux1  WESTOS_class2_linux3  WESTOS_class2_linux5
WESTOS_class1_linux2  WESTOS_class1_linux4  WESTOS_class1_linux6  WESTOS_class2_linux2  WESTOS_class2_linux4  WESTOS_class2_linux6
                                    ##查看是否創建成功
2.管理剛纔信建立的文件要求如下
*)用一條命令把redhat_versionX中的帶有奇數的文件複製到桌面的SINGLE中
*)用一條命令把redhat_versionX中的帶偶數數的文件複製到/DOUBLE中
*)用一條命令把WESTOS_classX_linuxY中class1的文件一動到當前用戶桌面的CLASS1中
*)用一條命令把WESTOS_classX_linuxY中class2的文件一動到當前用戶桌面的CLASS2中                      1)[root@foundation98 Desktop]# mv /mnt/VERSION/redhat_version[1.3.5.7] /root/Desktop/SINGLE/ ##移動文件  [1.3.5.7]代表奇數文件
[root@foundation98 Desktop]# ls /root/Desktop/SINGLE/                        ##查看是否移動成功
redhat_version1  redhat_version3  redhat_version5  redhat_version7
    2)[root@foundation98 Desktop]# cp /mnt/VERSION/redhat_version[2.4.6.8] /DOUBLE/
[root@foundation98 Desktop]# ls /DOUBLE/
redhat_version2  redhat_version4  redhat_version6  redhat_version8
    3)[root@foundation98 Desktop]# mkdir /root/Desktop/CLASS1
[root@foundation98 Desktop]# mv /root/Desktop/study/WESTOS_class1* /root/Desktop/CLASS1/
[root@foundation98 Desktop]# mkdir /root/Desktop/CLASS2
[root@foundation98 Desktop]# mv /root/Desktop/study/WESTOS_class2* /root/Desktop/CLASS2/
[root@foundation98 Desktop]# ls /root/Desktop/CLASS1 /root/Desktop/CLASS2
/root/Desktop/CLASS1:
WESTOS_class1_linux1  WESTOS_class1_linux3  WESTOS_class1_linux5
WESTOS_class1_linux2  WESTOS_class1_linux4  WESTOS_class1_linux6

/root/Desktop/CLASS2:
WESTOS_class2_linux1  WESTOS_class2_linux3  WESTOS_class2_linux5
WESTOS_class2_linux2  WESTOS_class2_linux4  WESTOS_class2_linux6

3.備份/etc目錄中所有帶有名字帶有數字並且以.conf結尾的文件到桌面上的confdir中[root@foundation98 Desktop]# mv /etc/*[[:digit:]]*.conf /root/Desktop/confdir/
[root@foundation98 Desktop]# ls /root/Desktop/confdir/
e2fsck.conf  krb5.conf  mke2fs.conf  pbm2ppa.conf  pnm2ppa.conf
5.刪掉剛纔建立或者備份的所有文件

[root@foundation98 Desktop]# rm -fr /DOUBLE/
[root@foundation98 Desktop]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@foundation98 Desktop]# rm -fr /mnt/VERSION/
[root@foundation98 Desktop]# ls
1  CLASS1  CLASS2  confdir  SINGLE  study
[root@foundation98 Desktop]# ls /
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@foundation98 Desktop]# rm -fr /mnt/VERSION/ /root/Desktop/*

<<<第四單元練習>>>
1.在student用戶下執行find /etc -name passwd 命令,並管理其輸出要求如下:

        * 顯示所有正確輸出,屏蔽錯誤輸出
        * 保存正確數出到/mnt/find.out,錯誤數出到/mnt/find.err中
        * 建立/mnt/find.all文件,並且保存所有輸出到此文件中
        * 再次保存所有輸出到/mnt/find.all中,並且保持源文件內容  
        * 屏蔽此命令的所有輸出
        * 顯示此命令的所有輸出並保存輸出到桌面上的任意文件中
        * 保存正確輸出到/mnt/find.out.1中,屏蔽錯誤輸出


  1.     1)[student@localhost ~]$ find /etc/ -name passwd 2>/dev/null
    /etc/passwd
    /etc/pam.d/passwd
        2)[student@localhost ~]$ find /etc/ -name passwd >/mnt/find.out  ##輸出正確結果到/mnt/find.out
    [student@localhost ~]$ find /etc/ -name passwd 2>/mnt/find.err         ##輸出錯誤結果到/mnt/find。err
        3)[student@localhost ~]$ find /etc/ -name passwd &>/mnt/find.all   ##&>爲輸出重定向所有結果
        4)[student@localhost ~]$ find /etc/ -name passwd &>>/mnt/find.all  ##&>>爲輸出所有結果並且不覆蓋源文件
    [student@localhost ~]$ cat /mnt/find.all
    find: ‘/etc/pki/CA/private’: Permission denied
    find: ‘/etc/pki/rsyslog’: Permission denied
    find: ‘/etc/audit’: Permission denied
    /etc/passwd
    find: ‘/etc/polkit-1/rules.d’: Permission denied
    find: ‘/etc/polkit-1/localauthority’: Permission denied
    find: ‘/etc/grub.d’: Permission denied
    find: ‘/etc/selinux/targeted/modules/active’: Permission denied
    /etc/pam.d/passwd
    find: ‘/etc/lvm/archive’: Permission denied
    find: ‘/etc/lvm/backup’: Permission denied
    find: ‘/etc/lvm/cache’: Permission denied
    find: ‘/etc/dhcp’: Permission denied
    find: ‘/etc/firewalld’: Permission denied
    find: ‘/etc/audisp’: Permission denied
    find: ‘/etc/sudoers.d’: Permission denied
    find: ‘/etc/ipsec.d’: Permission denied
    find: ‘/etc/libvirt’: Permission denied
    find: ‘/etc/cups/ssl’: Permission denied
    find: ‘/etc/pki/CA/private’: Permission denied
    find: ‘/etc/pki/rsyslog’: Permission denied
    find: ‘/etc/audit’: Permission denied
    /etc/passwd
    find: ‘/etc/polkit-1/rules.d’: Permission denied
    find: ‘/etc/polkit-1/localauthority’: Permission denied
    find: ‘/etc/grub.d’: Permission denied
    find: ‘/etc/selinux/targeted/modules/active’: Permission denied
    /etc/pam.d/passwd
    find: ‘/etc/lvm/archive’: Permission denied
    find: ‘/etc/lvm/backup’: Permission denied
    find: ‘/etc/lvm/cache’: Permission denied
    find: ‘/etc/dhcp’: Permission denied
    find: ‘/etc/firewalld’: Permission denied
    find: ‘/etc/audisp’: Permission denied
    find: ‘/etc/sudoers.d’: Permission denied
    find: ‘/etc/ipsec.d’: Permission denied
    find: ‘/etc/libvirt’: Permission denied
    find: ‘/etc/cups/ssl’: Permission denied
        5)[student@localhost ~]$ find /etc/ -name passwd &>/dev/null    ##此時屏幕上沒有輸出
        6)find /etc/ -name passwd 2>&1|tee /home/student/file        ##管道無法通過錯誤的輸出,故需要將錯誤的輸出轉換爲正確的輸出後通過tee命令將輸出拷貝到指定文件中
        7)[student@localhost ~]$ find /etc/ -name passwd 2>/dev/null |tee /mnt/find.out1   ##將錯誤的輸出倒入/dev/null中 將正確的輸出進行拷貝
    /etc/passwd
    /etc/pam.d/passwd
    [student@localhost ~]$ cat /mnt/find.out1
    /etc/passwd
    /etc/pam.d/passwd

2.處理文件在文件/usr/share/mime/packages/freedesktop.org.xml要求如下:

       *找到此文件中包含ich的行,並保存這些行到/root/lines

       *vim替換掉/root/lines中的空格,但要保持文件中原有的內容

        #grep ich /usr/share/mime/packages/freedesktop.org.xml >/root/lines

         vim /root/lines

          :%s/^\ *//g


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章