1.Linux上的文件管理類型命令都有哪些,其常用的使用方法及其相關示例演示
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2.bash的工作特性之命令執行后狀態返回值和命令展開所涉及的內容及其示例演示
命令執行的狀態結果:
bash通過狀態返回值來輸出此結果:
成功:0
失?。?-255
命令執行完成之后,其狀態返回值保存于bash的特殊變量$?中;
命令正常執行時,有的還回有命令返回值:
根據命令及其功能不同,結果各不相同;
[root@localhost ~]# ls /etc/sysconfig
anaconda?? ebtables-config?? irqbalance ? network???????? selinux
authconfig firewalld???????? kdump?????? network-scripts sshd
cbq???????? grub???????????? kernel???? rdisc?????????? wpa_supplicant
console???? init???????????? man-db???? readonly-root
cpupower?? ip6tables-config modules?? ? rsyslog
crond?????? iptables-config?? netconsole ? run-parts
[root@localhost ~]# echo $?
0
[root@localhost ~]# ls /etc/sysconfigg
ls: cannot access /etc/sysconfigg: No such file or directory
[root@localhost ~]# echo $?
2
[root@localhost ~]# lss /etc/sysconfig
-bash: lss: command not found
[root@localhost ~]# echo $?
127
3.請命令行展開功能來完成以下練習:
(1)創建/tmp下 a_c a_d b_c b_d
[root@localhost ~]# mkdir -v /tmp{a,b}_{c,d}
mkdir: created directory ‘/tmpa_c’
mkdir: created directory ‘/tmpa_d’
mkdir: created directory ‘/tmpb_c’
mkdir: created directory ‘/tmpb_d’
(2)創建/tmp/mylinux目錄下的:
[root@localhost ~]# mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib
/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}
mkdir: created directory ‘/tmp/mylinux’
mkdir: created directory ‘/tmp/mylinux/bin’
mkdir: created directory ‘/tmp/mylinux/boot’
mkdir: created directory ‘/tmp/mylinux/boot/grub’
mkdir: created directory ‘/tmp/mylinux/dev’
mkdir: created directory ‘/tmp/mylinux/etc’
mkdir: created directory ‘/tmp/mylinux/etc/rc.d’
mkdir: created directory ‘/tmp/mylinux/etc/rc.d/init.d’
mkdir: created directory ‘/tmp/mylinux/etc/sysconfig’
mkdir: created directory ‘/tmp/mylinux/etc/sysconfig/network-scripts’
mkdir: created directory ‘/tmp/mylinux/lib’
mkdir: created directory ‘/tmp/mylinux/lib/modules’
mkdir: created directory ‘/tmp/mylinux/lib64’
mkdir: created directory ‘/tmp/mylinux/proc’
mkdir: created directory ‘/tmp/mylinux/sbin’
mkdir: created directory ‘/tmp/mylinux/sys’
mkdir: created directory ‘/tmp/mylinux/tmp’
mkdir: created directory ‘/tmp/mylinux/usr’
mkdir: created directory ‘/tmp/mylinux/usr/local’
mkdir: created directory ‘/tmp/mylinux/usr/local/bin’
mkdir: created directory ‘/tmp/mylinux/usr/local/sbin’
mkdir: created directory ‘/tmp/mylinux/var’
mkdir: created directory ‘/tmp/mylinux/var/lock’
mkdir: created directory ‘/tmp/mylinux/var/log’
mkdir: created directory ‘/tmp/mylinux/var/run’
4.文件元數據信息有哪些,分別表示什么含義,如何查看,如何修改文件的時間戳信息
文件:每一文件都有兩類數據
元數據:metadata
數據: data
|
|
|
|
|
|
|
5.如何定義一個命令別名,如何在引用另一個命令的執行結果
命令別名:
獲取所有可用別名的定義:
[root@localhost ~]# alias
alias cp=’cp -i’
alias egrep=’egrep –color=auto’
alias fgrep=’fgrep –color=auto’
alias grep=’grep –color=auto’
alias l.=’ls -d .* –color=auto’
alias ll=’ls -l –color=auto’
alias ls=’ls –color=auto’
alias mv=’mv -i’
alias rm=’rm -i’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’
定義別名:
[root@localhost ~]# alias cls=clear
[root@localhost ~]# alias
alias cls=’clear’
alias cp=’cp -i’
alias egrep=’egrep –color=auto’
alias fgrep=’fgrep –color=auto’
alias grep=’grep –color=auto’
alias l.=’ls -d .* –color=auto’
alias ll=’ls -l –color=auto’
alias ls=’ls –color=auto’
alias mv=’mv -i’
alias rm=’rm -i’
alias which=’alias | /usr/bin/which –tty-only –read-alias –show-dot –show-tilde’
注意:定義別名使用小寫,如果命令之間沒有空格,不需要加單引號,但僅對當前shell進程有效
引用命令的執行結果:
$(COMMAND)
或`COMMAND`
[root@localhost ~]# date
Tue Dec 5 18:23:28 CST 2017
[root@localhost ~]# date +%T
18:23:46
[root@localhost ~]# date +%H-%M-%S
18-24-44
[root@localhost ~]# mkdir $(date +%H-%M-%S)
[root@localhost ~]# ls
18-25-29 anaconda-ks.cfg
[root@localhost ~]# mkdir $(date +%H-%M-%S)
[root@localhost ~]# ls
18-25-29 18-25-50 ? anaconda-ks.cfg
[root@localhost ~]# mkdir `date +%H-%M-%S`
[root@localhost ~]# ls
18-25-29 18-25-50 ? 18-27-01 anaconda-ks.cfg
6.顯示/var目錄下以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可有其它字符)的文件或目錄
[root@localhost ~]# ls -d /var/l*[[:digit:]]*[[:lower:]]
7.顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄
[root@localhost ~]# ls -d /etc/[0-9]*[^0-9]
8.顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄
[root@localhost ~]# ls /etc/[^a-z][a-z]*
9.在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22
[root@localhost ~]# mkdir -pv /tmp/tfile-$(date +”%F-%H-%M-%S”)
mkdir: created directory ‘/tmp/tfile-2017-12-10-18-22-43’
[root@localhost ~]# ls -d /tmp/tfile*[0-9]
/tmp/tfile-2017-12-10-18-22-43
[root@localhost ~]# touch /tmp/file-$(date +”%F-%H-%M-%S”)
[root@localhost ~]# ls -d /tmp/tfile*[0-9]
/tmp/tfile-2017-12-10-18-22-43
[root@localhost ~]# touch /tmp/tfile-$(date +”%F-%H-%M-%S”)
[root@localhost ~]# ls -d /tmp/tfile*[0-9]
/tmp/tfile-2017-12-10-18-22-43 /tmp/tfile-2017-12-10-18-26-16
10.復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中
[root@localhost ~]# mkdir /tmp/mytest1
[root@localhost ~]# cp -a /etc/p*[^0-9] /tmp/mytest1/
[root@localhost ~]# ls -d /tmp/mytest1/*
/tmp/mytest1/pam.d???? /tmp/mytest1/pm???????????? /tmp/mytest1/printcap
/tmp/mytest1/passwd?? /tmp/mytest1/popt.d???????? /tmp/mytest1/profile
/tmp/mytest1/passwd- ?/tmp/mytest1/postfix???????? /tmp/mytest1/profile.d
/tmp/mytest1/pki???? ? /tmp/mytest1/ppp?????????? ? /tmp/mytest1/protocols
/tmp/mytest1/plymouth /tmp/mytest1/prelink.conf.d /tmp/mytest1/python
[root@localhost ~]# \cp -rf /etc/p*[^0-9] /tmp/mytest1/
[root@localhost ~]# ls -d /tmp/mytest1/*
/tmp/mytest1/pam.d???? /tmp/mytest1/pm???????????? /tmp/mytest1/printcap
/tmp/mytest1/passwd?? /tmp/mytest1/popt.d???????? /tmp/mytest1/profile
/tmp/mytest1/passwd- ?/tmp/mytest1/postfix???????? /tmp/mytest1/profile.d
/tmp/mytest1/pki???? ? /tmp/mytest1/ppp?????????? ? /tmp/mytest1/protocols
/tmp/mytest1/plymouth /tmp/mytest1/prelink.conf.d /tmp/mytest1/python
11.復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中
[root@localhost ~]# mkdir -v /tmp/mytest2
mkdir: created directory ‘/tmp/mytest2’
[root@localhost ~]# ls -d /etc/*.d
/etc/bash_completion.d ? /etc/ld.so.conf.d?? /etc/rc0.d???? /etc/rwtab.d
/etc/binfmt.d???????? ? /etc/logrotate.d???? /etc/rc1.d???? /etc/statetab.d
/etc/chkconfig.d?????? ? /etc/modprobe.d???? /etc/rc2.d???? /etc/sudoers.d
/etc/cron.d?????????? ? /etc/modules-load.d /etc/rc3.d???? /etc/sysctl.d
/etc/depmod.d???????? ? /etc/my.cnf.d?????? /etc/rc4.d???? ? /etc/tmpfiles.d
/etc/dracut.conf.d???? ? /etc/pam.d?????????? /etc/rc5.d???? /etc/xinetd.d
/etc/grub.d?????????? ? /etc/popt.d???????? /etc/rc6.d???? /etc/yum.repos.d
/etc/init.d???????????? /etc/prelink.conf.d /etc/rc.d
/etc/krb5.conf.d?????? /etc/profile.d?????? /etc/rsyslog.d
[root@localhost ~]# cp -a /etc/*.d /tmp/mytest2
[root@localhost ~]# ls -d /tmp/mytest2/*
/tmp/mytest2/bash_completion.d /tmp/mytest2/modules-load.d /tmp/mytest2/rc6.d
/tmp/mytest2/binfmt.d?????????? /tmp/mytest2/my.cnf.d?????? /tmp/mytest2/rc.d
/tmp/mytest2/chkconfig.d?????? /tmp/mytest2/pam.d?????????? /tmp/mytest2/rsyslog.d
/tmp/mytest2/cron.d???????????? /tmp/mytest2/popt.d???????? /tmp/mytest2/rwtab.d
/tmp/mytest2/depmod.d?????????? /tmp/mytest2/prelink.conf.d /tmp/mytest2/statetab.d
/tmp/mytest2/dracut.conf.d???? /tmp/mytest2/profile.d?????? /tmp/mytest2/sudoers.d
/tmp/mytest2/grub.d???????????? /tmp/mytest2/rc0.d???????? ? /tmp/mytest2/sysctl.d
/tmp/mytest2/init.d?????????? ? /tmp/mytest2/rc1.d???????? ? /tmp/mytest2/tmpfiles.d
/tmp/mytest2/krb5.conf.d?????? /tmp/mytest2/rc2.d???????? ? /tmp/mytest2/xinetd.d
/tmp/mytest2/ld.so.conf.d?????? /tmp/mytest2/rc3.d???????? ? /tmp/mytest2/yum.repos.d
/tmp/mytest2/logrotate.d?????? /tmp/mytest2/rc4.d
/tmp/mytest2/modprobe.d???????? /tmp/mytest2/rc5.d
12.復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件或目錄至/tmp/mytest3目錄中
[root@localhost ~]# mkdir -v /tmp/mytest3
mkdir: created directory ‘/tmp/mytest3’
[root@localhost ~]# ls -d /etc/[lmn]*.conf
/etc/ld.so.conf???? /etc/libuser.conf /etc/logrotate.conf /etc/mke2fs.conf
/etc/libaudit.conf /etc/locale.conf?? /etc/man_db.conf???? /etc/nsswitch.conf
[root@localhost ~]# cp -a /etc/[lmn]*.conf /tmp/mytest3
[root@localhost ~]# ls -d /tmp/mytest3/*
/tmp/mytest3/ld.so.conf???? /tmp/mytest3/locale.conf???? /tmp/mytest3/mke2fs.conf
/tmp/mytest3/libaudit.conf /tmp/mytest3/logrotate.conf /tmp/mytest3/nsswitch.conf
/tmp/mytest3/libuser.conf ? /tmp/mytest3/man_db.conf
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/89813
總結很詳細的一篇。繼續加油~