在CentOS中,若是在拷貝(cp)或移動(mv)文件時使用了星號(*),則所指定通配起始目錄下的隱藏文件將沒法被通配失效,若有如下目錄:shell
[root@test source]# pwd /root/source
經過ls -l命令查看非隱藏文件:post
[root@test source]# ls -l total 0 -rw-r--r--. 1 root root 0 Jan 18 14:52 textfile01 -rw-r--r--. 1 root root 0 Jan 18 14:52 textfile02
在用ls -la命令查看全部文件(包含隱藏文件):code
[root@test source]# ls -al total 8 drwxr-xr-x. 2 root root 4096 Jan 18 14:52 . dr-xr-x---. 5 root root 4096 Jan 18 14:51 .. -rw-r--r--. 1 root root 0 Jan 18 14:52 .hiddenfile -rw-r--r--. 1 root root 0 Jan 18 14:52 .htaccess -rw-r--r--. 1 root root 0 Jan 18 14:52 textfile01 -rw-r--r--. 1 root root 0 Jan 18 14:52 textfile02
其中.hiddenfile和.htaccess爲隱藏文件(實際上.和..也是隱藏文件)。咱們先建立一個目標目錄,用於存放拷貝內容:ip
[root@test source]# cd .. [root@test ~]# mkdir target [root@test ~]# ls -l total 8 drwxr-xr-x. 2 root root 4096 Jan 18 14:52 source drwxr-xr-x. 2 root root 4096 Jan 18 14:57 target
而後開始用星號(*)嘗試拷貝:get
[root@test ~]# cp -rf source/* target/ [root@test ~]# ls -al target/ total 8 drwxr-xr-x. 2 root root 4096 Jan 18 14:59 . dr-xr-x---. 4 root root 4096 Jan 18 14:57 .. -rw-r--r--. 1 root root 0 Jan 18 14:59 textfile01 -rw-r--r--. 1 root root 0 Jan 18 14:59 textfile02
可見,拷貝失敗了。class
兩個解決思路:test
1.在星號前加」.」,以顯式地聲明須要通配的是隱藏文件。但這種方法須要人爲地過濾掉’.'和’..’,不然就是死循環。
2.不用星號(*)通配,而直接選定目錄做爲拷貝目標,在上例中爲:file
[root@test ~]# cp -rf source/ target [root@test ~]# ls -al target/ total 8 drwxr-xr-x. 2 root root 4096 Jan 18 15:04 . dr-xr-x---. 4 root root 4096 Jan 18 15:04 .. -rw-r--r--. 1 root root 0 Jan 18 15:04 .hiddenfile -rw-r--r--. 1 root root 0 Jan 18 15:04 .htaccess -rw-r--r--. 1 root root 0 Jan 18 15:04 textfile01 -rw-r--r--. 1 root root 0 Jan 18 15:04 textfile02
#注意cp的目標是target和不是target/,讀者能夠嘗試二者的不一樣。循環