在删除除主要版本号之外的所有文件时查找并复制所有文件

时间:2017-03-25 18:43:32

标签: linux shell

尝试使用"找到"复制一堆共享对象。几乎在那里,但想要删除除主要版本之外的所有版本号。 例如somesharedobject.so.30.0.4复制到somesharedobject.so.30

find . -maxdepth 1 -type f -name '*.so.*' -exec cp '{}' test/'{}' \;

我猜我不得不去管xargs和sed,但只是打了一个精神障碍。

find . -maxdepth 1 -type f -name '*.so.*'|xargs -I '{}' cp '{}' test/'{}'

2 个答案:

答案 0 :(得分:1)

想想我会选择这样的事情 var request = (albumId != '') ? {requestType: 'Album', id: albumId} : {requestType: 'Image', id: imageId}; 似乎从我的测试中可以正常工作

答案 1 :(得分:0)

我会编写一个函数+脚本来简化工作

#!/bin/bash
specialised_copy(){
version="${1##*so.}"
# extract the version part alone in the above step
cp "$1" "test/${1%%.so*}.so.${version%%.*}" 
#cut the major version part from the version and use it for copy
#note folder test should be relative to where the script is saved
}
export -f specialised_copy
find . -maxdepth 1 -type f -name '*.so.*' -exec bash -c 'specialised_copy "$1"' _ {} \;