开发者

Bash copying files with variables

New to bash scripting, I'm writing a script to copy my TV shows accross from a download folder to an archive folder.

So far I have this:

find `*`show1`*`.avi |  cp \"" $0 "\" "/mnt/main/data/tv/Show1" 
find `*`show2`*`.avi |  cp \"" $0 "\" "/mnt/main/data/tv/Show2"

I understand this is not the best method, but my skills of bash are quite limited.

I need to know how I can copy that found file, or do nothing if it doesnt find anything matching (this will be a cron script). eg.

find `*`show1`*`.avi |  cp "show1.hello.world.xvid.avi" "/mnt/main/data/tv/Show1" 
find `*`show2`*`.avi |  cp "show2.foo.bar.xvid.avi" "/mnt/main/data/tv/Show2" 
find `*`show3`*`.avi |  cp "null (nothing found)" "/mnt/main/data/tv/Show3"
开发者_运维技巧

Thanks!

EDIT: Solved http://pastebin.com/aNLihR86


find . -name "*show1*" -exec cp {} /mnt/main/data/tv/Show1 \;

(Replace the . by the directory you want to look files into)


Bash 4+

shopt -s globstar
shopt -s nullglob
for file in **/*show*
do
  case "$file" in
   *show1* ) dest="/mnt/main/data/tv/Show1" ;;
   *show2* ) dest="/mnt/main/data/tv/Show2" ;;
   *show3* ) dest="/mnt/main/data/tv/Show2";;
  esac
  cp "$file" "$dest"
done
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜