1

I have versioned files which come out of a build pipeline.

foo-1.3.4.war

and I need to move these files to have the name

foo-dev-1.3.4.war

How would I go about this?

I was thinking something like mv foo-*.war foo-dev-*.war but this will only create the files with *.

Any Ideas?

2

Using just bash and commands in most common distributions by default:

find . -name "foo-*.war" -exec sh -c 'mv "$1" "other_folder/foo-dev-${1#foo-}"' _ {} \;

3

This worked for me - could also be done with find instead of ls:

  #touch foo-1.3.{1..10}.war
  #ls -1
  foo-1.3.10.war
  foo-1.3.1.war
  foo-1.3.2.war
  foo-1.3.3.war
  foo-1.3.4.war
  foo-1.3.5.war
  foo-1.3.6.war
  foo-1.3.7.war
  foo-1.3.8.war
  foo-1.3.9.war

  #for fil in $(ls -1); do 
     filNew=$(echo $fil | sed 's/foo/foo-dev/g');
     mv $fil $filNew;
   done

  #ls -1
  foo-dev-1.3.10.war
  foo-dev-1.3.1.war
  foo-dev-1.3.2.war
  foo-dev-1.3.3.war
  foo-dev-1.3.4.war
  foo-dev-1.3.5.war
  foo-dev-1.3.6.war
  foo-dev-1.3.7.war
  foo-dev-1.3.8.war
  foo-dev-1.3.9.war
1

You could use Perl implementation of rename program (there is another program called rename which is a part of util-linux package) like that:

$ touch foo-1.3.{1..10}.war
$ ls -l
total 0
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.1.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.10.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.2.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.3.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.4.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.5.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.6.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.7.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.8.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-1.3.9.war
$ rename 's,^foo,foo-dev,' *
$ ls -l
total 0
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.1.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.10.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.2.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.3.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.4.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.5.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.6.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.7.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.8.war
-rw-r--r-- 1 ja users 0 Sep  9 19:14 foo-dev--1.3.9.war

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.