Batch renaming files in command line and Xargs

后端 未结 9 738
余生分开走
余生分开走 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:21

    Coming late to the party, but here's how you can rename files with xargs. Say you have a bunch of files named fileN.svg.png and you want to name them fileN.png where N could be a series of integers:

    ls *.svg.png | xargs basename -s .svg.png | xargs -I {} mv {}.svg.png {}.png

    The first xargs uses basename to strip off both .svg and .png to get a just filenameN. The second xargs receives that bare name and uses replacement to rename the file.

提交回复
热议问题