壁紙画像を単一のフォルダにコピー

壁紙画像を単一のフォルダにコピー

私のUbuntu 12.04設定には、ディレクトリに多くの壁紙画像があります/usr/share/wallpapers。たとえば、次のようになります。

usr/share/wallpapers/Leafs_Labyrinth/contents/images/1600x1200.jpg

私がやりたいことは、壁紙ディレクトリを繰り返しながらサイズ指定されたすべての画像を選択するか、1600x...別の1680x...フォルダにコピーして名前を変更して上記の画像を呼び出すことですLeafs_Labyrinth1600x1200.jpg

ここでは一人ではできませんfind。ある種のシェルスクリプトを使用する必要があるようですが、それについての経験はほとんどありません。これを行う簡単な「自然な」方法はありますか?

ベストアンサー1

これはあなたの質問の詳細に基づいて機能します。以下をファイルに保存して変更できます。私のディレクトリ宛先フォルダの名前で次を実行しますbash name_of_script

#!/bin/bash

# * matches any string | [08] matches 0 and 8
for image in /usr/share/wallpapers/*/contents/images/16[08]0x*.jpg; do
    # create variables by cutting $image in pieces separated by /
    name=$(awk -F/ '{print $5}' <<<$image)
    file=$(awk -F/ '{print $8}' <<<$image)

    # copy to "mydirectory"
    cp "$image" mydirectory/"$name""$file"
done

次のように単純化することもできます。

for image in /usr/share/wallpapers/*/contents/images/16[08]0x*.jpg; do
    cp "$image" mydirectory/"$(awk -F/ '{print $5 $8}' <<<$image)"
done

おすすめ記事