初入Linux,M35作業第二彈,課後實驗練習常用命令,牛刀小試
練習
1、顯示當前時間,格式:2016-06-18 10:20:30
2、顯示前天是星期幾
3、設定當前日期為2019-08-07 06:05:10
答:1、[[email protected] ~]#date "+%F %T"
2018-12-15 01:12:29
2、[[email protected] ~]#date -d "-2 day" +%w
4
3、[
2019-08-07 06:05:10
=================分割線===================
練習:
*1:在本機字元終端登入時,除顯示原有資訊外,再顯示當前登入終端號,主機名和當前時 間
*2:今天18:30自動關機,並提示使用者
答:1、[[email protected] ~]#> /etc/profile.d/env.sh
[
PS1="\[\e[1;35m\][\[email protected]\l \H \w \t]\\$\[\e[0m\]"
[[email protected] ~]#. /etc/profile.d/env.sh
[[email protected]
2、[[email protected] 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、[[email protected] ~]#ls /var/l*[0-9]*[[:lower:]]
/var/l23xp /var/la99la /var/ll23xp
2、[[email protected] ~]#ls -d /etc/[0-9]*[^0-9]
/etc/22la99la /etc/2la99la
3、[[email protected] ~]#ls -d /etc/[^a-Z][a-Z]*
/etc/2la99la
或者[[email protected] ~]#ls -d /etc/[^[:alpha:]][[:alpha:]]*
/etc/2la99la
4、[[email protected] ~]#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、[[email protected] ~]# 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、[[email protected] ~]#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、[[email protected] ~]#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、[[email protected] ~]#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、[[email protected] ~]#alias baketc='\cp -rfv /etc /data/backup`date +%F`'
[[email protected] ~]#baketc
...... #此行是可見的備份過程
[[email protected] ~]#ls /data
backup2018-12-17
2、[[email protected] ~]#mkdir -p /data/rootdir/
[[email protected] ~]#\cp -a /root/* /data/rootdir/
[[email protected] ~]#ls /data
backup2018-12-17 rootdir
[[email protected] ~]#ls /root
anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates 老鐵
Desktop Downloads Music Public Videos
[[email protected] ~]#ls /data/rootdir/
anaconda-ks.cfg Documents initial-setup-ks.cfg Pictures Templates 老鐵
Desktop Downloads Music Public Videos