サブフォルダをコピーせずに「cp -R」を使用してすべてのファイルをサブフォルダにコピーするには?

サブフォルダをコピーせずに「cp -R」を使用してすべてのファイルをサブフォルダにコピーするには?

画像のサイズを変更できるように、独自のサブフォルダにコピーしたい画像フォルダがあります。

次のようになります。

$ ls
100x100                                 image1.png
image2.png                              image3.png
image4.png                              pic1.jpg

私が経験している問題は、コマンドを実行するとデフォルトでcp -R ./. 100x100100x100フォルダをそれ自体に追加できないというエラーが発生することです。

cp: 100x100/./100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/100x100/.DS_Store: name too long (not copied)

cp -Rサブフォルダもコピーせずにファイルをサブフォルダにコピーする方法は?

答え1

シェルが次の場合zsh(macosを使用している場合):

set -o extendedglob # best in ~/.zshrc
cp -- {^,}100x100

次に拡張予定:

cp -- ^100x100 100x100

つまり、すべてのファイル100x100100x100

隠しファイルもコピーします。

cp -- ^100x100(D) 100x100

通常のファイル(ディレクトリ、シンボリックリンクなど)のみをコピーします。

cp -- ^100x100(D.) 100x100

答え2

使用cp ./*.* ./100x100 いいえこのオプションは、ディレクトリをそれ自体にコピーするのではなく、ディレクトリ内の-Rすべてのファイルをサブディレクトリにコピーします。100x100

この-Rオプションは、すべてのサブディレクトリをターゲットに繰り返しコピーするために使用され、これが発生しないようにするために使用しないでください。

man cpこのコマンドのオプションと使用方法の詳細については、リソースを参照してください。

関連情報