When using * in bash how do I output to the same file
up vote
0
down vote
favorite
I'm trying to use the command convert -resize 1024X768 source.png dest.jpg
on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png
but I'd like to know how to supply the same filename as the destination.
I'm only using the convert command as an example.
bash
add a comment |Â
up vote
0
down vote
favorite
I'm trying to use the command convert -resize 1024X768 source.png dest.jpg
on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png
but I'd like to know how to supply the same filename as the destination.
I'm only using the convert command as an example.
bash
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to use the command convert -resize 1024X768 source.png dest.jpg
on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png
but I'd like to know how to supply the same filename as the destination.
I'm only using the convert command as an example.
bash
I'm trying to use the command convert -resize 1024X768 source.png dest.jpg
on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png
but I'd like to know how to supply the same filename as the destination.
I'm only using the convert command as an example.
bash
bash
edited Mar 11 at 0:01
asked Mar 9 at 22:16
user3927312
1094
1094
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
You can try with a for
command line
Test with a 'dry run',
for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done
and when its output looks good, remove echo
and do the conversion,
for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done
Alternative with find
and rename
If you want to avoid a loop in bash, you can use find
,
find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;
and when its output looks good, remove echo and do the conversion,
find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;
After that you can use rename
to make the target file names nicer (prune the clumsy double extension)
rename -n s/.png.jpg$/.jpg/ *.png.jpg
and when its output looks good, remove -n
and do the real renaming,
rename s/.png.jpg$/.jpg/ *.png.jpg
There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
You can try with a for
command line
Test with a 'dry run',
for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done
and when its output looks good, remove echo
and do the conversion,
for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done
Alternative with find
and rename
If you want to avoid a loop in bash, you can use find
,
find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;
and when its output looks good, remove echo and do the conversion,
find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;
After that you can use rename
to make the target file names nicer (prune the clumsy double extension)
rename -n s/.png.jpg$/.jpg/ *.png.jpg
and when its output looks good, remove -n
and do the real renaming,
rename s/.png.jpg$/.jpg/ *.png.jpg
There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
add a comment |Â
up vote
6
down vote
accepted
You can try with a for
command line
Test with a 'dry run',
for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done
and when its output looks good, remove echo
and do the conversion,
for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done
Alternative with find
and rename
If you want to avoid a loop in bash, you can use find
,
find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;
and when its output looks good, remove echo and do the conversion,
find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;
After that you can use rename
to make the target file names nicer (prune the clumsy double extension)
rename -n s/.png.jpg$/.jpg/ *.png.jpg
and when its output looks good, remove -n
and do the real renaming,
rename s/.png.jpg$/.jpg/ *.png.jpg
There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
You can try with a for
command line
Test with a 'dry run',
for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done
and when its output looks good, remove echo
and do the conversion,
for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done
Alternative with find
and rename
If you want to avoid a loop in bash, you can use find
,
find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;
and when its output looks good, remove echo and do the conversion,
find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;
After that you can use rename
to make the target file names nicer (prune the clumsy double extension)
rename -n s/.png.jpg$/.jpg/ *.png.jpg
and when its output looks good, remove -n
and do the real renaming,
rename s/.png.jpg$/.jpg/ *.png.jpg
There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.
You can try with a for
command line
Test with a 'dry run',
for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done
and when its output looks good, remove echo
and do the conversion,
for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done
Alternative with find
and rename
If you want to avoid a loop in bash, you can use find
,
find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;
and when its output looks good, remove echo and do the conversion,
find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;
After that you can use rename
to make the target file names nicer (prune the clumsy double extension)
rename -n s/.png.jpg$/.jpg/ *.png.jpg
and when its output looks good, remove -n
and do the real renaming,
rename s/.png.jpg$/.jpg/ *.png.jpg
There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.
edited Mar 10 at 8:50
answered Mar 9 at 22:39
sudodus
20.4k32668
20.4k32668
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
add a comment |Â
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
â user3927312
Mar 10 at 1:15
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
@user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
â sudodus
Mar 10 at 8:17
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1013526%2fwhen-using-in-bash-how-do-i-output-to-the-same-file%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password