馬哥教育網絡班20期+第二周博客作業

1.Linux上的文件管理類命令 
2.bash命令學習總結 
3.bash命令實例 
4.元數據與時間戳 
5.命令別名 
6.練習題6~12


1.Linux上的文件管理類命令

       Linux上的文件管理類命令可分為查看類、目錄管理類、權限管理類、文本處理類。

1.1 查看類命令

ls: 用于顯示目錄 
用法: ls [OPTION]… [FILE]… 
選項: 
       -a: 顯示所有文件包括隱藏文件 
       ll : 顯示目錄詳細信息

[root@MyCloudServer ~]# ls /usr  
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp

pwd: 顯示當前工作目錄 
用法: pwd [DIR]…

[root@MyCloudServer ~]# pwd
/root

cat: 用于察看文本內容 
用法: cat [OPTION]… [FILE]…

[root@MyCloudServer ~]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m

more: 與cat命令相似,逐頁顯示文本 
用法: more [OPTION]… [FILE]…

[root@MyCloudServer etc]# more yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
--More--(91%)

less: 與more命令相似,不同的是可往回瀏覽 
用法: less [OPTION]… [FILE]…

[root@MyCloudServer etc]# less yum.conf
#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
(END)

head: 從頭開始顯示文本內容,默認前10行 
用法:* head [OPTION]… [FILE]… 
選項: 
        -c #: 指定獲取前#字節 
        -n #: 指定獲取前#行

[root@MyCloudServer etc]# head -n 5 yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log

tail: 與head相似,從尾部開始顯示文本內容 
用法: tail [OPTION]… [FILE]… 
選項: 
        -c #: 指定獲取前#字節 
        -n #: 指定獲取前#行 
        -f : 跟蹤顯示文件新追加的內容

[root@MyCloudServer etc]# tail -n 5 yum.conf
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

echo: 將內容輸出到屏幕

[root@MyCloudServer etc]# echo yum.conf
yum.conf

1.2 目錄及文件管理類命令

cd: 可用于目錄之間的切換 
用法: cd [DIR]… 
選項: 
        cd 或 cd ~: 回當前用戶主目錄 
        cd ~USERNAME: 切換指定用戶目錄 
        cd -:在上一個目錄和當前目錄之間來回切換 在上一個目錄和當前目錄之間來回切換

[root@MyCloudServer etc]# cd /opt
[root@MyCloudServer opt]#

mkdir: 用于創建目錄 
用法: mkdir [DIR]… 
選項: 
        -p: 由于創建多級目錄

[root@MyCloudServer tmp]# mkdir c/d
mkdir: cannot create directory `c/d': No such file or directory
[root@MyCloudServer tmp]# mkdir -p c/d

rmdir:刪除空目錄 
用法: rmdir [DIR]…

[root@MyCloudServer tmp]# rmdir c/d

cp:用于復制文件或目錄到指定位置 
用法: cp [OPTION]… /PATH/[DIR or FILE]… /PATH/ 
選項: 
        -r: 遞歸復制目錄及內部的所有內容 
        -f: –force

[root@MyCloudServer tmp]# cp /etc/yum.conf /tmp

mv:用于移動文件或目錄到指定位置,可以將文件或目錄重命名 
用法: mv /PATH/[DIR or FILE]… /PATH/

[root@MyCloudServer tmp]# mv 1 a/b
[root@MyCloudServer tmp]# mv a/b/1   a/b/2    #重命名

rm: 刪除命令 
用法: mv [OPTION]… /PATH/[DIR or FILE] 
選項: 
        -r: 遞歸刪除目錄及內部的所有內容 
        -f: –force

[root@MyCloudServer tmp]# rm -rf c/4

1.3 權限管理類

chmod:用于修改文件或目錄權限 
用法: chmod [OPTION]… MODE[,MODE]… FILE… 
MODE: 
rwx  111  7 r–  100  4 –x  001  1 
rw-  110  6 -wx  011 3 —  000  0 
r-x  101   5 -w-  010  2

[root@MyCloudServer tmp]# ll
total 12
drwxr-xr-x  3 root root 4096 Jun 19 07:06 a
drwxr-xr-x  2 root root 4096 Jun 19 07:11 c
-rw-r--r--  1 root root  969 Jun 19 07:16 yum.conf
-rw-------. 1 root root    0 Dec 21  2011 yum.log
[root@MyCloudServer tmp]# chmod 111 yum.log
[root@MyCloudServer tmp]# ll
total 12
drwxr-xr-x  3 root root 4096 Jun 19 07:06 a
drwxr-xr-x  2 root root 4096 Jun 19 07:11 c
-rw-r--r--  1 root root  969 Jun 19 07:16 yum.conf
---x--x--x. 1 root root    0 Dec 21  2011 yum.log

chown:修改文件或目錄的屬主,屬組 
chown [OPTION]… [OWENER]:[GROUP] FILE… 
用法: 
選項: 
       -R: 遞歸

[root@MyCloudServer tmp]# chown CentOS:CentOS a
[root@MyCloudServer tmp]# ll
total 12
drwxr-xr-x  3 CentOS CentOS 4096 Jun 19 07:06 a
drwxr-xr-x  2 root   root   4096 Jun 19 07:11 c
-rw-r--r--  1 root   root    969 Jun 19 07:16 yum.conf
---x--x--x. 1 root   root      0 Dec 21  2011 yum.log

1.4 文本處理類

cut: 從文本每一行上移除部分內容,選擇性顯示結果 
用法: cut [OPTION]… [FILE]… 
選項: 
        -d DELIMITER: 指明分隔符 
        -f FILEDS: 
                #: 第#個字段 
               #,#[,#]:離散的多個字段,例如1,3,6 
               #-#: 連續的多個字段,例如1-6 
               混合使用:1-3,7

[root@MyCloudServer ~]# cut -d: -f 1 /etc/passwd
root
bin
daemon
adm
lp
sync

wc:統計指定文本的行數、字節數、字數,并將結果顯示輸出 
用法: wc [OPTION]… [FILE]… 
選項: 
        -l : 統計行數 
        -w: 統計單詞數 
        -c: 統計字節數

[root@MyCloudServer ~]# wc -l /etc/passwd
20 /etc/passwd
[root@MyCloudServer ~]# wc -w /etc/passwd
26 /etc/passwd
[root@MyCloudServer ~]# wc -c /etc/passwd
898 /etc/passwd

sort:幫助我們將不同數據類型排序 
用法: wc [OPTION]… [FILE]… 
選項: 
        -f: 忽略字符大小寫 
        -r: 逆序 
        -t DELIMITER: 字段分隔符 
        -k #: 以指定字段排序 
        -n: 以數值大小排序 
        -u: 排序后去重

[root@MyCloudServer ~]# sort -f -r /etc/passwd
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
saslauth:x:499:499:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
root:x:0:0:root:/root:/bin/bash
postfix:x:89:89::/var/spool/postfix:/sbin/nologin

uniq: 顯示或刪除重復的行 
用法: uniq [OPTION]… [FILE]… 
選項: 
        -c: 顯示每行重復出現的次數; 
        -d: 僅顯示重復過的行; 
        -u: 僅顯示不曾重復的行;

[root@MyCloudServer tmp]# uniq -u 1
b
c
d
[root@MyCloudServer tmp]# uniq -d 1
a
e

2.bash命令學習總結

bash的基礎特性:

2.1、命令補全 
        bash執行命令分為內建命令與外部命令 
2.2、命令歷史:history

[root@MyCloudServer tmp]# history
1  yum install wget -y
2  ping baidu.com
...
341  tree mylinux
342  history

CTRL+R:快速搜索歷史命令

(reverse-i-search)`rm': rm -rf mylinux

快速重復執行上一條命令 
       有 4 種方法可以重復執行上一條命令: 
       使用上方向鍵,并回車執行。 
       按 !! 并回車執行。 
       輸入 !-1 并回車執行。 
       按 Ctrl+P 并回車執行 
。 
如果你想清除所有的命令歷史: history -c

2.3、路徑補全:Tab 
直接補全:所需補全的內容為唯一時,直接補全;如果內容不為唯一時,再按一次Tab給出列表

2.4、命令行展開: 
~ :展開為用戶的主目錄 
~ HOMENAME:展開指定用戶的家目錄 
{}:以逗號分隔,并展開為多個路徑

2.5、命令的執行狀態結果 
       成功:0 
       失敗:1-255 
       echo $?:輸出狀態結果 
        程序執行的結果有兩類:返回值與執行狀態結果。

2.6、命令別名:alias 
詳情見 5.命令別名

2.7、glob

golb用于實現bash文件名的“通配”

       *:表示任意數量個字符 
       ?:表示一個字符 
       []:指定[]范圍內的字符 
       [^]:指定[^]范圍外的字符 
              [^0-9a-z]:表示除0-9,a-z,用來表示特殊字符

專用字符集 
       [:digit:]:0-9 
       [:lower:]:任意小寫字母 
       [:upper:]:任意大寫字母 
       [:alpha:]:任意大小寫字母 
       [:alnum:]:任意數字或字母 
       [:space:]:空格 
       [:punct:]:標點符號

2.8、I/O重定與管道

I/0重定分為輸入(Input)與輸出(Output)重定

輸入重定的用法: 
COMMAND < FILE:從命令從文件中讀入

[root@MyCloudServer tmp]# cat < 2
cat /etc/passwd

COMMAND << EOF:從命令行輸入直到匹配到EOF為止

[root@MyCloudServer tmp]# cat << EOF
> /etc/passwd
> EOF
/etc/passwd

輸出重定的用法: 
COMMAND > FILE:將COMMAND命令的輸出到FILE中,如果FILE不為空,則清空FILE后再寫入

[root@MyCloudServer tmp]# cat 2
HI~
[root@MyCloudServer tmp]# cat 1 > 2
[root@MyCloudServer tmp]# cat 2
HELLO WORLD~

COMMAND >> FILE:將COMMAND命令的輸出追加到FILE原有信息后

[root@MyCloudServer tmp]# cat 1 >> 2 
[root@MyCloudServer tmp]# cat 2
HELLO WORLD~
HELLO WORLD~

2.9、配置文件

按生效范圍可分為兩類: 
全局配置: 
       /etc/profile 
       /etc/bashrc 
個人配置: 
       ~/.bash_profile 
       ~/.bashrc

按功能劃分可分為兩類: 
profile:為交互式提供配置 
       (1) 定義環境變量 
       (2) 運行腳本或命令 
生效順序:/etc/profile –> /etc/profile.d/*.sh –> ~/.bash_profile –> ~/.bashrc –> /etc/bashrc

bashrc:為非交互式提供配置 
       (1) 定義命令別名 
       (2) 定義本地變量 
生效順序:~/.bashrc –> etc/bashrc –> etc/profile.d/*.sh

2.10、運算符

常用的運算: 
+,-,, /, %, *

算術運算的實現: 
let var = 算術表達式

[root@MyCloudServer tmp]# cat 3
#!/bin/bash
#
let test=1+3
echo $test
[root@MyCloudServer tmp]# ./3
4

運算的測試類型: 
       數據型: 
              -gt:大于 
              -ge:大于等于 
              -lt:小于 
              -le:小于等于 
              -eq:等于 
              -ne:不等于 
       字符型: 
              ==:等于 
              >:大于 
              <:小于 
              !=:不等于 
              =~:左側字符能否匹配到右側字符 
              -z:是否為空 
              -n:是否為不空

2.11、條件測試與邏輯運算

條件測試的用法: 
test EXPRESSION 
[ EXPRESSION ] 
[[ EXPRESSON ]]

[root@MyCloudServer tmp]# [ -a 1 ]&& echo yes || echo no
yes

文件測試: 
       存在性測試 
              -a FILE: 
              -e FILE: 
       存在及類型測試 
              -b FILE:存在且為塊文件 
              -c FILE:存在且為字符型設備文件 
              -d FILE:存在且為為目錄文件 
              -f FILE:存在且為為普通文件 
              -h FILE:存在且為符號鏈接文件 
              -p FILE:存在且為命令管道文件 
              -S FILE:存在且為套接字文件 
       文件權限測試: 
              -r FILE:存在且為可讀 
              -w FILE:存在且為可寫 
              -x FILE:存在且為可執行 
       文件特殊權限: 
              -g FILE:存在且為sgid 
              -u FILE:存在且為suid 
              -k FILE:存在且為sticky 
       文件大小測試: 
              -s FILE:存在且為非空

邏輯運算的兩種方式: 
第一種方式: 
COMMAND1 && COMMAND2 
COMMAND1 || COMMAND2 
! COMMAND

[root@MyCloudServer tmp]# [ -r 1 ] && [ -f 1 ]
[root@MyCloudServer tmp]# echo $?
0

第二種方式: 
EXPRESSION1 -a EXPRESSION2 
EXPRESSION1 -o EXPRESSION2 
!EXPRESSION

[root@MyCloudServer tmp]# [ -r 1 -a -f 1  ]
[root@MyCloudServer tmp]# echo $?
0

2.12、文件查找

文件查找可分類為兩類: 
       非實時查找:local 
              依賴于事先構建的索引,需要自動更新或手工更新DB,索引的構建需要遍歷整個根文件系統,極耗資源

       實時查找:find 
              通過遍歷指定路徑來完成查找

find的用法: 
find [OPTION]… [PATH]…[EXPRESSION]

根據文件名: 
       -name "NAME"

[root@MyCloudServer tmp]# find -name linuxtest
./linuxtest

       -iname "NAME":不區分大小寫

[root@MyCloudServer tmp]# find -iname linuxtest
./linuxtest
./LiNuxTesT

根據屬主、屬組查找 
       -user USERNAME:屬主 
       -group GROUPNAME:屬組 
       -uid UID:UID號 
       -gid GID:GID號 
       -nouser:查找沒有屬主的文件 
       -nogroup:查找沒有屬組的文件

可以用2.11 條件測試與邏輯運算里的文件測試與邏輯測試的相關參數

2.13、腳本與變量

變量的類型: 
強類型:定義變量時必須指定類型,參與運算必須符合類型要求,調用未聲明變量會產生錯誤 
弱類型:無須指定類型,默認為字符型,參與運算里會自動隱式類型轉換

變量的賦值: 
(1) 可以直接賦值:NAME = "VALUE" 
(2) 可以引用變量:NAME = "$VALUE" 
(3) 可以引用命令:NAME = 'COMMAND' , NAME = $(COMMAND) 
強引用 '' :其中變量不會被引用,保持原字符串 
弱引用 "" : 其中變量會被替換成變量的值 
set:顯示所有定義的變量 
unset NAME:銷毀指定的變量 
$[1,2..]:調用對應參數 
$0:命令本身

只讀變量: 
       readonly name 
       declare -r name

腳本:

[root@MyCloudServer tmp]# ls
1  3.sh  a_d  b_d        LiNuxTesT  tree-1.5.3-3.el6.x86_64.rpm  yum.log
2  a_c   b_c  linuxtest  mylinux    yum.conf
[root@MyCloudServer tmp]# ./3.sh      #執行腳本
yes
[root@MyCloudServer tmp]# cat 3.sh    #察看腳本內容
#!/bin/bash
#
[ -a 1 ]&& echo yes || echo no

3.bash使用實例

(1) 創建/tmp目錄下的: a_c, a_d, b_c, b_d

[root@MyCloudServer tmp]# mkdir {a,b}_{c,d}
[root@MyCloudServer tmp]# ls
1  a_c  a_d  b_c  b_d  yum.conf  yum.log

(2) 創建/tmp/mylinux目錄下的 
mylinux/ 
bin 
boot 
        grub 
dev 
etc 
        re.d 
                init.d 
        sysconfig 
                network-scripts 
lib 
        modules 
lib64 
proc 
sbin 
sys 
tmp 
usr 
        local 
                bin 
                sbin 
var 
        lock 
        log 
        run

[root@MyCloudServer tmp]# rm -rf mylinux
[root@MyCloudServer tmp]# mkdir -p mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-script},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}
[root@MyCloudServer tmp]# tree mylinux
mylinux
├── bin
├── boot
│   └── grub
├── dev
├── etc
│   ├── rc.d
│   │   └── init.d
│   └── sysconfig
│       └── network-script
├── lib
│   └── modules
├── lib64
├── proc
├── sbin
├── sys
├── tmp
├── usr
│   └── local
│       ├── bin
│       └── sbin
└── var
    ├── lock
    ├── log
    └── run

4.元數據與時間戳

4.1 元數據

ll:用來描述一個文件的系統特征,如訪問權限,文件數據分布等。 
用法: ll [FILE]

[root@MyCloudServer tmp]# ll 1
-r---w---x  1 root root 13 Jun 19 15:52 1

-r—w—x 1 root root 13 Jun 19 15:52 1 便是文件1的元數據信息 
-  :文件類型,參考2.11 條件測試與邏輯運算里的文件測試 
r– :屬主權限,r為可讀 
w–:屬組權限, w為可寫 
–x :其它,x為可執行 
1    :表示硬鏈接數量 
root:第一個root表示屬主 
root:第二個root表示屬組 
13   :為文件d大小 
Jun 19 15:52:為時間 
1    :最后一位表示文件名

時間戳:通常是一個字符序列,唯一標識某一刻的時間。

4.2 時間戳

第一類系統時間:

date:顯示或修改系統時間 
用法: date [OPTION]… [+FORMAT] 或者 date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]

[root@MyCloudServer tmp]# date
Sun Jun 19 17:53:43 CST 2016
[root@MyCloudServer tmp]# date '+%D'
06/19/16
[root@MyCloudServer tmp]# date '+%F'
2016-06-19
[root@MyCloudServer tmp]# date '+%T'
17:56:55

[root@MyCloudServer tmp]# date -s 20160619 #設置成20160619  
[root@MyCloudServer tmp]# date -s 10:13:10 #設置具體時間
[root@MyCloudServer tmp]# date -s "10:13:10 20160619" #設置全部時間
[root@MyCloudServer tmp]# ntpdate xxx.xxx.xxx.xxx #同步xxx.xxx.xxx.xxx IP地址的時間

第二類文件時間:

stat:顯示文件狀態 
用法: stat [FILE]…

[root@MyCloudServer tmp]# stat 1
File: `1'
Size: 13              Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 259795      Links: 1
Access: (0421/-r---w---x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-06-19 18:12:50.465801870 +0800
Modify: 2016-06-19 18:12:50.465801870 +0800
Change: 2016-06-19 18:12:50.465801870 +0800

touch: 可用于修改時間戳 
用法: touch [OPTION]… [FILE]… 
選項: 
     -a: 改讀取文件內容變atime 
     -m: 改變mtime 
     -t STAMP: 指明要變為的時間 
     -c: 如果文件不存在,則不予創建

[root@MyCloudServer tmp]# touch -t 201411121249.50 -a 1
[root@MyCloudServer tmp]# stat 1
  File: `1'
  Size: 13              Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 259795      Links: 1
Access: (0421/-r---w---x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-11-12 12:49:50.000000000 +0800
Modify: 2016-06-19 18:12:50.465801870 +0800
Change: 2016-06-19 18:22:30.231802498 +0800

5.命令別名

5.1 alias顯示當前進程可用所有別名列表 
用法: alias

[root@MyCloudServer tmp]# alias
alias cp='cp -i'
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'

5.2 定義別名 
用法: alisa NAME='COMMAND'

[root@MyCloudServer tmp]# alias test='ls /tmp'
[root@MyCloudServer tmp]# test
1  a_c  a_d  b_c  b_d  mylinux  tree-1.5.3-3.el6.x86_64.rpm  yum.conf  yum.log

Note:在命令行中定義的別名,僅對當前shell進程有效 
       僅對當前用戶:~/.bashrc 
       對所有用戶有效:/etc/bashrc

bash進程重新讀取配置文件; 
       source /PATH/TO/CONFIG_FILE 
       ./PATH/TO/CONFIG_FILE

5.3 定義別名并在命令中引用另一個命令的執行結果

[root@MyCloudServer tmp]# ls mydata
ls: cannot access mydata: No such file or directory
[root@MyCloudServer opt]# alias test='cd /tmp/mydata >>/dev/null 2>&1'
[root@MyCloudServer tmp]# test
[root@MyCloudServer tmp]# [ $? == 0 ]&&echo exits||echo no exits
no exits

6.習題6~12

6.6、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可有其它字符)的文件或目錄

[root@MyCloudServer var]# ls
cache  empty  l.123p  l23.p   lib    lock  mail  opt       run    tmp
db     games  l.231p  l342.p  local  log   nis   preserve  spool  yp
[root@MyCloudServer var]# ls -d /var/l*[0-9]*[[:lower:]]
/var/l.123p  /var/l.231p  /var/l23.p  /var/l342.p

6.7、顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄

[root@MyCloudServer etc]# touch 123sf
[root@MyCloudServer etc]# touch 12345
[root@MyCloudServer etc]# mkdir 23456
[root@MyCloudServer etc]# mkdir 234sf
[root@MyCloudServer etc]# ls -d /etc/[0-9]*[^0-9]
/etc/123sf  /etc/234sf

6.8、顯示/etc/目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄

[root@MyCloudServer etc]# touch 1fdsf
[root@MyCloudServer etc]# mkdir 2f123
[root@MyCloudServer etc]# ls -d /etc/[^a-zA-Z][[:alpha:]]*
/etc/1fdsf  /etc/2f123

6.9、在/tmp目錄下創建以tfile開頭,后面跟當前日期時間的文件,文件名如tfile-2016-5-27-09-32-22

[root@MyCloudServer etc]# touch /tmp/tfile-`date "+%Y-%m-%d-%H-%M-%S"`
[root@MyCloudServer etc]# ls /tmp
2  3.sh  a_d  b_d     linuxtest  mylinux  tfile-2016-06-19-19-38-29    yum.conf
3  a_c   b_c  l324.p  LiNuxTesT  stat     tree-1.5.3-3.el6.x86_64.rpm  yum.log

6.10、復制/etc目錄下所有p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中

[root@MyCloudServer etc]# cp -r /etc/p*[^0-9] /tmp/mytest1
[root@MyCloudServer etc]# ls /tmp/mytest1
pam.d   passwd-  plymouth  popt.d   ppp       profile    protocols
passwd  pki      pm        postfix  printcap  profile.d

6.11、復制/etc目錄下所有以.d結尾的文件或目錄到/tmp/mytest2目錄中

[root@MyCloudServer etc]# cp -r /etc/*.d /tmp/mytest2
[root@MyCloudServer etc]# ls /tmp/mytest2
bash_completion.d  dracut.conf.d  makedev.d   profile.d  rc3.d  rc.d        sudoers.d
chkconfig.d        init.d         modprobe.d  rc0.d      rc4.d  rsyslog.d   xinetd.d
cron.d             ld.so.conf.d   pam.d       rc1.d      rc5.d  rwtab.d     yum.repos.d
depmod.d           logrotate.d    popt.d      rc2.d      rc6.d  statetab.d

6.12、復制/etc目錄下所有以l或m或n開頭,以.conf結尾的文件到/tmp/mytest3目錄中

[root@MyCloudServer etc]# cp /etc/[l,m,n]*.conf /tmp/mytest3
[root@MyCloudServer etc]# ls /tmp/mytest3
ld.so.conf  libaudit.conf  libuser.conf  logrotate.conf  mke2fs.conf  nsswitch.conf

原創文章,作者:laiwen2007,如若轉載,請注明出處:http://www.www58058.com/18611

(0)
laiwen2007laiwen2007
上一篇 2016-06-19 11:32
下一篇 2016-06-19 17:46

相關推薦

  • 馬哥教育網絡21期+第三周練習博客

    馬哥教育網絡21期+第三周練習博客 一.回顧第二周的學習內容 1,Linux上的文件管理類的命令: mkdir:創建目錄: [root@localhost ~]# mkdir /tmp/fstab2222 [root@localhost ~]# ls -l /tmp/ total&nbsp…

    Linux干貨 2016-07-16
  • linux 基礎命令(四)

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何訪問權限。 [root@localhost home]# cp -r /etc/skel/ /home/tuser1 [root@localhost home]# c…

    Linux干貨 2016-10-16
  • Linux 網絡管理

    Linux 網絡管理 第一篇:計算機網絡基礎: 一、計算機網絡: 1.TCP/IP:協議棧(使用中的模型)     ISO(國際標準化組織):OSI(開放系統互聯基本參考模型),學習中的模型。           1)各層之間的相關協議和單位:     互聯網…

    Linux干貨 2016-09-06
  • 22期網絡班+第一周作業+深圳+王金寶

    1、描述計算機的組成及其功能? 答: 顯示器和主機,顯示器就不說了 主機里又有,主板,又叫主機板(mainboard)、系統板(systembourd)和母板(motherboard);它安裝在機箱內,是微機最基本的也是最重要的部件之一。主板一般為矩形電路板,上面安裝了組成計算機的主要電路系統,一般有BIOS芯片、I/O控制芯片、鍵盤和面板控制開關 接口、指…

    Linux干貨 2016-08-13
  • keepalived+lvs 實現站點高可用

    lvs實現負載均衡
    keepalived 解決 director單點和realserver監控檢測

    2017-12-13

評論列表(5條)

  • zhutoyearn
    zhutoyearn 2016-06-19 21:42

    挺好的,參考你的寫一個

  • zhutoyearn
    zhutoyearn 2016-06-19 22:06

    cp:用于復制文件或目錄到指定位置
    用法: rmdir [OPTION]… /PATH/[DIR or FILE]… /PATH/

    用法這里寫成rmdir了

    • laiwen2007
      laiwen2007 2016-06-20 07:25

      @zhutoyearn恩,多謝指教

  • 馬哥教育
    馬哥教育 2016-06-21 22:42

    寫的很好,非常棒,可以在多關注一些排版,如果能在列舉一些命令的常用選項那就更好了,加油!

  • Net20_天意
    Net20_天意 2016-06-22 14:32

    值得借鑒~~~特別好

欧美性久久久久