home.


Tagged: unix-xargs


Bulk renaming files in Android Asset Studio download

If you use Roman Nurik’s wonderful Android Asset Studio, you’ll get a downloaded zip of differently sized icons.

You may want to rename these files from ic_launcher.png to something else - otherwise it may clash with an existing file of that name.

You can use xargs to do this. Move to the directory of the downloaded file, in the res directory and run this:

ls | xargs -I {} mv {}ic_launcher.png {}YOUR_NEW_FILENAME.png

We list each mipmap-xxxx directory, and rename all the ic_launcher.png files within to our new filename.

android unix-xargs

Unix: Access piped parameter with xargs

When you pipe something to xargs you normally don’t need to access its name, since it’s added to the end of the command:

echo 'hiya' | xargs echo 'i said'

This would print ‘i said hiya’.

If you want to access the passed parameter, ‘hiya’, you can do so by passing -i to xargs, and using {}:

echo 'hiya' | xargs -i echo ' {} was just said'

This would print ‘hiya was just said’.

unix unix-xargs

Unix: Counting lines in a directory including sub directories

Below will look for all the java files in the src/ directory, piping each file found to ‘wc -l’ which will count the lines there.

You get a total at the bottom.

$ find src/ -name '*.java' | xargs wc -l
   31 src/main/java/org/denevell/rocklobster/BlogFileCreationUtils.java
   20 src/main/java/org/denevell/rocklobster/BlogMarkdownUtils.java
   86 src/main/java/org/denevell/rocklobster/utils/ClassUtils.java
   39 src/main/java/org/denevell/rocklobster/utils/PaginationUtils.java
   30 src/main/java/org/denevell/rocklobster/utils/LogUtils.java
   51 src/main/java/org/denevell/rocklobster/utils/FileUtils.java
   42 src/main/java/org/denevell/rocklobster/utils/GitUtils.java
   42 src/main/java/org/denevell/rocklobster/utils/MetadataUtils.java
   39 src/main/java/org/denevell/rocklobster/plugins/SinglePageTagsPlugin.java
   45 src/main/java/org/denevell/rocklobster/plugins/PrettyDatePlugin.java
   48 src/main/java/org/denevell/rocklobster/plugins/AllTagsPlugin.java
   52 src/main/java/org/denevell/rocklobster/plugins/infrastructure/TemplatePluginsContextImpl.java
   10 src/main/java/org/denevell/rocklobster/plugins/infrastructure/Plugin.java
    8 src/main/java/org/denevell/rocklobster/plugins/infrastructure/TemplatePluginsContext.java
   55 src/main/java/org/denevell/rocklobster/blogposts/BlogPost.java
   68 src/main/java/org/denevell/rocklobster/templates/PaginatedPageTemplate.java
   58 src/main/java/org/denevell/rocklobster/templates/SinglePageTemplate.java
   42 src/main/java/org/denevell/rocklobster/templates/PageTemplate.java
   33 src/main/java/org/denevell/rocklobster/templates/FilteredPaginatedPageTemplate.java
   86 src/main/java/org/denevell/rocklobster/templates/infrastructure/FilteredPaginatedPageTemplateFactory.java
   25 src/main/java/org/denevell/rocklobster/templates/infrastructure/SinglePageTemplateFactory.java
   48 src/main/java/org/denevell/rocklobster/templates/infrastructure/PaginatedPageTemplateFactory.java
   30 src/main/java/org/denevell/rocklobster/templates/infrastructure/PageTemplateFactory.java
   54 src/main/java/org/denevell/rocklobster/Main.java
  129 src/main/java/org/denevell/rocklobster/BlogPostParsing.java
 1171 total
unix unix-wc unix-xargs

Page 1 of 1