我試圖將「file.txt」文件複製到所有目錄中。爲什麼我在cp命令中使用globbing獲得「omitting directory」錯誤?
[[email protected]]# ls -lh
total 132K
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:47 ilo01
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo02
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo03
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo04
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo05
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo06
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo07
drwxr--r--. 2 postgres postgres 4.0K Jan 2 08:40 ilo08
drwxr--r--. 2 postgres postgres 4.0K Jan 2 10:03 ilo09
drwxr--r--. 11 postgres postgres 4.0K Jan 2 11:15 ilo10
-rw-r--r--. 1 postgres postgres 64K Jun 27 2016 file.txt
使用TAB鍵才能看到該命令的行爲來運行:
[[email protected]]# cp -p file.txt ilo[0-1][0-9]
ilo01/ ilo02/ ilo03/ ilo04/ ilo05/ ilo06/ ilo07/ ilo08/ ilo09/ ilo10/
但我得到這個錯誤:
[[email protected]]# cp -v -p file.txt ilo[0-1][0-9]*
`postgresTdas.txt' -> `ilo10/file.txt'
cp: omitting directory `ilo01'
cp: omitting directory `ilo02'
cp: omitting directory `ilo03'
cp: omitting directory `ilo04'
cp: omitting directory `ilo05'
cp: omitting directory `ilo06'
cp: omitting directory `ilo07'
cp: omitting directory `ilo08'
cp: omitting directory `ilo09'
同樣的事情發生的:
[[email protected]]# cp -p file.txt ilo*
和
[[email protected]]# cp -p file.txt ilo*/
我不明白爲什麼「[0-1] [0-9]不按我需要的方式工作。
我假設副本將把tab.txt放在TAB顯示的列表中。
我錯過了什麼?
'cp'可以將一個或多個文件複製到單個目標目錄,或者它可以將文件複製到單個目標文件。它不能將單個文件複製到多個目標。您需要創建一個循環將您的文件複製到所有這些目錄。 – codeforester
你可以在這裏找到你的答案:http://stackoverflow.com/questions/195655/how-to-copy-a-file-to-multiple-directories-using-the-gnu-cp-command – codeforester
謝謝。我對這個問題感到非常慚愧:/ – manuelc