特定のファイル拡張子を持つすべてのファイルをサブディレクトリから単一のディレクトリに移動する方法

特定のファイル拡張子を持つすべてのファイルをサブディレクトリから単一のディレクトリに移動する方法

home/andhra1/node1/*.txtファイルhome/andhra1/noden/*.txthome/andhra2/node1/*.txt他のサブディレクトリ内のすべてのファイルを1つのディレクトリにコピーする必要があります。

以下は私が書いたシェルスクリプトです。

fromPath='source path'
echo $fromPath
file='destination path/*.pdf'
echo $file
toPath='destination path'
echo $toPath
for i in $file;
do
  filePath=$i
  if [ -e $filePath ];
  then
    echo $filePath
    yes | cp -rf $filePath $toPath
  else
    echo 'no files'
  fi
done

ベストアンサー1

次のコードを試してください。

find /home/andhra1 -maxdepth 3 -name "*.txt" -type f -exec mv '{}' 
destinationPath/ \;

おすすめ記事