初入Linux,M35作业第二弹,课后实验练习常用命令,牛刀小试

练习
1、显示当前时间,格式:2016-06-18 10:20:30
2、显示前天是星期几
3、设置当前日期为2019-08-07 06:05:10

答:1、[root@centos6 ~]#date "+%F %T"
        2018-12-15 01:12:29
    2、[root@centos6 ~]#date -d "-2 day" +%w
        4
    3、[root@centos6 ~]#date -s "2019-08-07 06:05:10" "+%F %T"
        2019-08-07 06:05:10
=================分割线===================
练习:
*1:在本机字符终端登录时,除显示原有信息外,再显示当前登录终端号,主机名和当前时    间
*2:今天18:30自动关机,并提示用户

答:1、[root@centos7 ~]#> /etc/profile.d/env.sh
        [root@centos7 ~]#nano /etc/profile.d/env.sh
        PS1="\[\e[1;35m\][\u@\l \H \w \t]\\$\[\e[0m\]"
        [root@centos7 ~]#. /etc/profile.d/env.sh
        [root@1 centos7 ~ 12:38:41]#
       
    2、[root@1 centos7 ~ 12:38:51]#shutdown -h 18:30  the OS will be shutdown at 18:30
    Shutdown scheduled for Mon 2018-12-17 18:30:00 CST, use 'shutdown -c' to cancel.
   
=============================================
练习
1、显示/var目录下所有以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录
2、显示/etc目录下以任意一位数字开头,且以非数字结尾的文件或目录
3、显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件或目录
4、显示/etc/目录下所有以rc开头,并后面是0-6之间的数字,其它为任意字符的文件或目录
5、显示/etc目录下,所有以.d结尾的文件或目录
6、显示/etc目录下,所有.conf结尾,且以m,n,r,p开头的文件或目录
7、只显示/root下的隐藏文件和目录
8、只显示/etc下的非隐藏目录

答:1、[root@centos7 ~]#ls /var/l*[0-9]*[[:lower:]]
    /var/l23xp  /var/la99la  /var/ll23xp
    2、[root@centos7 ~]#ls -d /etc/[0-9]*[^0-9]
    /etc/22la99la  /etc/2la99la
    3、[root@centos7 ~]#ls -d /etc/[^a-Z][a-Z]*
        /etc/2la99la
    或者[root@centos7 ~]#ls -d     /etc/[^[:alpha:]][[:alpha:]]*                         
    /etc/2la99la
    4、[root@centos7 ~]#ls -d /etc/rc[0-6]*
    /etc/rc0.d  /etc/rc1.d  /etc/rc2.d  /etc/rc3.d  /etc/rc4.d  /etc/rc5.d  /etc/rc6.d
    5、[root@centos7 ~]# ls -d /etc/*.d
    /etc/bash_completion.d  /etc/ipsec.d         /etc/prelink.conf.d  /etc/rsyslog.d
    /etc/binfmt.d           /etc/krb5.conf.d     /etc/profile.d       /etc/rwtab.d
    /etc/chkconfig.d        /etc/ld.so.conf.d    /etc/rc0.d           /etc/sane.d
    /etc/cron.d             /etc/libibverbs.d    /etc/rc1.d           /etc/setuptool.d
    /etc/depmod.d           /etc/logrotate.d     /etc/rc2.d           /etc/statetab.d
    /etc/dnsmasq.d          /etc/modprobe.d      /etc/rc3.d           /etc/sudoers.d
    /etc/dracut.conf.d      /etc/modules-load.d  /etc/rc4.d           /etc/sysctl.d
    /etc/exports.d          /etc/my.cnf.d        /etc/rc5.d           /etc/tmpfiles.d
    /etc/gdbinit.d          /etc/oddjobd.conf.d  /etc/rc6.d           /etc/xinetd.d
    /etc/grub.d             /etc/pam.d           /etc/rc.d            /etc/yum.repos.d
    /etc/init.d             /etc/popt.d          /etc/request-key.d
    6、[root@centos7 ~]#ls /etc/[mnrp]*.conf
    /etc/man_db.conf  /etc/nfsmount.conf  /etc/pnm2ppa.conf      /etc/rsyncd.conf
    /etc/mke2fs.conf  /etc/nsswitch.conf  /etc/radvd.conf        /etc/rsyslog.conf
    /etc/mtools.conf  /etc/numad.conf     /etc/request-key.conf
    /etc/nfs.conf     /etc/pbm2ppa.conf   /etc/resolv.conf
    7、[root@centos7 ~]#ls -d /root/.*
    /root/.              /root/.bash_profile  /root/.cshrc         /root/.lesshst
    /root/..             /root/.bashrc        /root/.dbus          /root/.local
    /root/.bash_history  /root/.cache         /root/.esd_auth      /root/.tcshrc
    /root/.bash_logout   /root/.config        /root/.ICEauthority  /root/.viminfo
    8、[root@centos7 ~]#ls -d /etc/*/
    /etc/abrt/               /etc/iproute2/        /etc/rc1.d/
    /etc/alsa/               /etc/ipsec.d/         /etc/rc2.d/
    /etc/alternatives/       /etc/iscsi/           /etc/rc3.d/
    /etc/audisp/             /etc/java/            /etc/rc4.d/
    /etc/audit/              /etc/jvm/             /etc/rc5.d/
    /etc/avahi/              /etc/jvm-commmon/     /etc/rc6.d/
    /etc/bash_completion.d/  /etc/kernel/          /etc/rc.d/
   
=================================================
练习
1、定义别名命令baketc,每天将/etc/目录下所有文件,备份到/data独立的子目录下,并要求子目录格式为 backupYYYY-mm-dd,备份过程可见
2、创建/data/rootdir目录,并复制/root下所有文件到该目录内,要求保留原有权限

答:1、[root@centos7 ~]#alias baketc='\cp -rfv /etc /data/backup`date +%F`'
        [root@centos7 ~]#baketc
        ......   #此行是可见的备份过程
        [root@centos7 ~]#ls /data
        backup2018-12-17
       
    2、[root@centos7 ~]#mkdir -p /data/rootdir/
        [root@centos7 ~]#\cp -a /root/* /data/rootdir/
        [root@centos7 ~]#ls /data
        backup2018-12-17  rootdir
        [root@centos7 ~]#ls /root
        anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  Templates  老铁
        Desktop          Downloads  Music                 Public    Videos
        [root@centos7 ~]#ls /data/rootdir/
        anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  Templates  老铁
        Desktop          Downloads  Music                 Public    Videos

猜你喜欢

转载自blog.51cto.com/14127598/2331652