使用xargs的下面这命令和两个移动命令 [英] Using xargs command and two move commands following it
问题描述
操作系统:AIX
外壳:BSH
OS: aix shell: bsh
脂肪酶
我有两种类型的文件,一类结尾的 .pdf.marker 并与另一端的 .PDF
I have two types of files, one type ends with .pdf.marker and the other ends with .pdf
有应该总是使用相同的名称(只有扩展名不同)。
There should be always a pair with the same name (only the extensions are different).
当我移动 .pdf.marker 文件我也必须将其相应的 .PDF 文件。
When I move a .pdf.marker file I must also move its corresponding .pdf file.
我想是这样的:
find ${INPUT_LOCATION}/ -name "*.pdf.marker" | xargs -I file mv file ${OUTPUT_LOCATION}/. mv $(basename file .marker) ${OUTPUT_LOCATION}/.
然后我读这个: xargs的多个命令作为参数的
并试图像这样:
Then I read this: xargs with multiple commands as arguments and tried something like this:
find ${INPUT_LOCATION}/ -name "*.pdf.marker" | xargs -I file {mv file ${OUTPUT_LOCATION}/.; mv $(basename file .marker) ${OUTPUT_LOCATION}/.;}
但它仍然没有工作。
but it still didnt work.
我只需要xargs的后执行2命令。
I just need to execute 2 commands after xargs.
修改
继提出答案,我得到了我试图把仅有2参数为一个移动命令
以下xargs的,而不是两个独立的移动命令。
Following the proposed answers I got i tried to put just 2 parameters into one move command instead of two separate move commands following xargs.
find ${INPUT_LOCATION}/ -name "*.pdf.marker" | xargs -I file mv file $(basename file .marker) ${OUTPUT_LOCATION}/.
但现在,在 .pdf.marker 首先移动,然后当我尝试从文件名删除 .marker 以获得 .PDF 文件名,我收到了警告,没有这样的文件或目录。
But now, the .pdf.marker is moved first, then when I try to remove the .marker from the filename to get the .pdf filename i get a warning no such file or directory.
有另一种方式来获得的 .PDF 文件名字符串?
Is there another way to get .pdf filename string?
SOLUTION
find ${INPUT_LOCATION} -name '*.pdf.marker' -exec sh -c 'mv $0 `dirname $0`/`basename $0 .marker` $1' {} ${OUTPUT_LOCATION} \;
在CCA移动200 000文件。 25分钟。没有问题的。
Moved 200 000 files in cca. 25 min. without problems.
谢谢大家谁与他们的答案和十分感谢参加呈上对你纳韦尔Fouilleul!
Thanks everyone who participated with their answers and a big thanks goes to you Nahuel Fouilleul!
推荐答案
试试这个(用于调试x选项)
try this (x option for debug)
find "${INPUT_LOCATION}" -name '*.pdf.marker' | xargs -i bash -cx 'pdf=`dirname {}`/`basename {} .marker`;[ -e "$pdf" ]&&{ mv {} "$pdf" "$0";}' "${OUTPUT_LOCATION}"
或更短
find $INPUT_LOCATION -name '*.pdf.marker' | xargs -i bash -c 'mv ${0%.marker} $0 $1' {} $OUTPUT_LOCATION
或
find $INPUT_LOCATION -name '*.pdf.marker' -exec bash -c 'mv ${0%.marker} $0 $1' {} $OUTPUT_LOCATION \;
也许更标准
find ${INPUT_LOCATION} -name '*.pdf.marker' -exec sh -c 'mv $0 `dirname $0`/`basename $0 .marker` $1' {} ${OUTPUT_LOCATION} \;
和用于测试回声可以添加
and for tests echo can be added
find ${INPUT_LOCATION} -name '*.pdf.marker' -exec sh -c 'echo mv $0 `dirname $0`/`basename $0 .marker` $1' {} ${OUTPUT_LOCATION} \;
这篇关于使用xargs的下面这命令和两个移动命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!