画像のサイズを変更できるように、独自のサブフォルダにコピーしたい画像フォルダがあります。
次のようになります。
$ ls
100x100 image1.png
image2.png image3.png
image4.png pic1.jpg
私が経験している問題は、コマンドを実行するとデフォルトでcp -R ./. 100x100
100x100フォルダをそれ自体に追加できないというエラーが発生することです。
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
つまり、すべてのファイル100x100
を100x100
。
隠しファイルもコピーします。
cp -- ^100x100(D) 100x100
通常のファイル(ディレクトリ、シンボリックリンクなど)のみをコピーします。
cp -- ^100x100(D.) 100x100
答え2
使用cp ./*.* ./100x100
いいえこのオプションは、ディレクトリをそれ自体にコピーするのではなく、ディレクトリ内の-R
すべてのファイルをサブディレクトリにコピーします。100x100
この-R
オプションは、すべてのサブディレクトリをターゲットに繰り返しコピーするために使用され、これが発生しないようにするために使用しないでください。
man cp
このコマンドのオプションと使用方法の詳細については、リソースを参照してください。