Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Rename command tips for multiple files

add an extension to multiple files in different location:
   1  
   2  $ EXT=`date "+%m%d%y.%H.%M"`
   3  $ find . -type f -name "name" | xargs -i mv {} {}.$EXT

For example rename all *.bak file as *.txt, enter:
   1  $ rename .bak .txt *.bak

Remove all blank space with rename command:
   1  $ rename "s/ *//g" *.mp3

To remove .jpg file extension, you write command as follows:
   1  $ rename 's/\.jpg$//' *.jpg

To convert all uppercase filenames to lowercase:
   1  $ rename 'y/A-Z/a-z/' *

Linux Shell script to rename files

Before rename command I was using following shell script to rename my mp3s
   1  
   2  #!/bin/bash
   3  # To remove blank space
   4  if [ $# -eq 0 ];
   5  then
   6   echo "Syntax: $(basename $0) file-name [command]"
   7   exit 1
   8  fi
   9  FILES=$1
  10  CMD=$2
  11  for i in $FILES
  12  do
  13  # remove all blanks and store them OUT
  14  OUT=$(echo $i | sed 's/  *//g')
  15  if [ "$CMD" == "" ];
  16  then
  17  #just show file
  18  echo $OUT
  19  else
  20  #else execute command such as mv or cp or rm
  21  [ "$i" != "$OUT" ] && $($CMD  "$i"  "$OUT")
  22  fi
  23  done

rename *nix file using mv

You can use the unix
   1  mv
command to rename your files

   1  
   2  mv myfile.htm mynewfile.htm

Rename *nix filenames


I am a bit slow sometimes and it took me a while to find this unix command that most are probably already aware of. rename is a very useful tool. The example I have here will susbtitute "foo" for "bar" of any file with foo in the name. The really nice thing about this is that it can use and regular expression syntax (ie. "^", "$", etc..).

   1  
   2  rename -n 's/foo/bar/' *foo*

Nokia platform version

The way Nokia names their phone versions is rather confusing.
For example.
   1  Series 60 Platform 2nd edition feature pack 2


I wonder why don't they just use s60.2.2
Now, at least they have renamed 'Series 60' to 'S60'
which is a good step in the right direction.

So, I will tag all new python for series 60 scripts with
'python, s60' instead of the old 'python, series60'.
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS