Batch renaming files in command line and Xargs

后端 未结 9 725
余生分开走
余生分开走 2020-12-12 16:32

So, I have the following structure:

.
..
a.png
b.png 
c.png

I ran a command to resize them

ls | xargs -I xx convert xx -res         


        
9条回答
  •  庸人自扰
    2020-12-12 17:23

    To clean up your error, try the rename utility. Check the manpage for details.

    In your case, you'd do rename '.png.jpg' '.jpg' ./* if your current directory is set appropriately.

    Since you have convert available, I'm assuming you have mogrify too (imagemagick suite). Whenever I want to do this, I copy the files into a different directory and use mogrify instead. I usually need this only for resizing, but if you change the image format aswell, mogrify will handle the filenames (make new files with proper filenames).

    You would use it as mogrify -format jpg -resize [size] ./*.png. I'm not sure what -resize without geometry arguments is supposed to do. It isn't documented and doesn't work on my machine.

    As Tim Pote reasoned, I don't think you can make xargs handle filenames and extensions separately.

提交回复
热议问题