I'm trying to remove the file that I was working on previously but it's not letting me, please help. Here is the command I run:
find . -type f -name '*.flac' -print0 |
xargs -0i ffmpeg -i {} -acodec libmp3lame -ab 320k "{}.mp3" |
rm -rf {}
If you have GNU Parallel installed you can do:
find . -type f -name '*.flac' | parallel ffmpeg -i {} -acodec libmp3lame -ab 320k {.}.mp3 '&&' rm {}
It will run one ffmpeg process per CPU core.
To learn more watch the intro videos: http://pi.dk/1
upload
is the program you use to upload with): find . -type f -name '*.flac' | parallel ffmpeg -i {} -sameq {.}.mp4 '&&' upload {.}.mp4 '&&' rm {}
Aug 2, 2012 at 7:01
You are piping the output of the ffmpeg
call(s) into the rm
command. Since ffmpeg
produces no interesting output and rm
does not read any input, this doesn't do anything.
I'm not sure what you're trying to do. I think you want to remove the flac file after processing. You have several choices: you can first convert all the ffmpeg files, then remove them all; or you can remove each file after it's been processed. I advise the latter, otherwise it will be difficult to only remove the flac file if the conversion succeeded.
Rather than use xargs
, it's simpler to use find … -exec
here. For each flac file, call ffmpeg
, and then delete the file if ffmpeg succeeded. If your find doesn't have the -delete
action, use -exec rm {} \;
instead. Use an intermediate shell to construct the output file name.
find . -type f -name '*.flac' \
-exec sh -c 'ffmpeg -i "$0" -acodec libmp3lame -ab 320k "${0%.*}.mp3"' {} \; \
-delete
You can use the rm
command inside the shell snippet instead.
find . -type f -name '*.flac' \
-exec sh -c 'ffmpeg -i "$0" -acodec libmp3lame -ab 320k "${0%.*}.mp3" && rm "$0"' {} \;
With some versions of find
, if you want the output file to be called foo.flac.mp3
, you can skip the intermediate shell.
find . -type f -name '*.flac' \
-exec ffmpeg -i {} -acodec libmp3lame -ab 320k {}.mp3 \; \
-delete
The command rm
doesn't take input from standard input, so you need to send it input using xargs
just like you did for ffmpeg
try this:
find . -type f -name '*.flac' -print0 |
xargs -0i bash -c 'ffmpeg -i {} -acodec libmp3lame -ab 320k \"{}.mp3" ; rm -rf {}'
This adds rm
into the command xargs
executes, essentially creating an inline shell script using bash -c
.
First of all, "it's not letting me" is not the best way to describe the problem. You should post the error message or describe what happens.
Second, I don't quite get what you're trying to achieve, but you're not using rm
with xargs
, you just pipe something to rm
. That's not how rm
works.
find . -type f -name '*.flac' -print0 | xargs -0i rm "{}"
would probably work, for example. I'm not using rm -r
here, because find
only looks for files anyway.