简体   繁体   中英

Renaming and moving wildcard files with Bash

I'm trying to do the following with this bash script but i've come unstuck..

1) Find every file with the extension .mp3 in the /usr/incoming/ directory

2) Use eyeD3 to strip all of the existing ID3 tags

3) Use eyeD3 to write a title tag "NEW NAME" back to the file

4) Use mv to rename every file with the extension .mp3 to latest.mp3 and then force move it (so it will overwrite any other file with the same name) to the usr/complete directory.

It's all working apart from the last bit (No.4).

I know i'm doing something wrong with the mv command but I'm not sure what.

Here's the code :

 find /usr/incoming/ -name '*.mp3' \
   -exec eyeD3 --remove-all -t 'NEW NAME' '{}' \; \
   -exec mv -f '*.mp3' latest.mp3 /usr/complete \;

Can anybody show me the error of my ways? ;)

Change the *.mp3 in your later command to {} to pass in an explicit name of the file you just tagged. mv will refuse to rename multiple files to the same name in a single invocation -- when passed more than two arguments, it requires the last to be a directory -- and anyhow, anything given as an argument to find's -exec is passed as a literal argument, not through a shell, so globs aren't expanded, redirections aren't processed, etc. except for find's own special strings such as {} .

find /usr/incoming/ -name '*.mp3' \
   -exec eyeD3 --remove-all -t 'NEW NAME' {} ';' \
   -exec mv -f {} /usr/complete/latest.mp3 ';'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM