sim*_*ico 7 osx find cp wildcards
我想将所有.html
文件myDir
及其子目录复制到~/otherDir
. 这是我尝试过的,但不起作用:
$ find myDir -name *.html -print | xargs -0 cp ~/otherDir
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
Run Code Online (Sandbox Code Playgroud)
Mil*_*ach 12
首先,shell 正在为你通配 '*'。使用\
或使用引号将其转义*.html
像这样:
find myDir -name "*.html"
或者 find myDir -name \*.html
跳过使用xargs
withfind
的-exec
开关:
find myDir -name "*.html" -exec cp {} ~/otherDir \;
这是有效的,因为{}
它取代了find
找到的文件,并且为每个匹配执行一次。
另请注意,这将使源目录的副本变平。例子:
myDir/a.html
myDir/b/c.html
Run Code Online (Sandbox Code Playgroud)
会屈服
otherdir/a.html
otherdir/c.html
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11161 次 |
最近记录: |