This is a test version of Biostars. For the public version, visit https://www.biostars.org.
renaming files and including folder/directory name in it

Hello,

I have 500 folders and each folder contains about 5 files. I want to rename those files and include folder name with it.

For example:

My folders (sample1_1, sample2_2, sample3_3) look like this:

sample1_1: bin.1.permissive.fa bin2.orig.fa

sample2_2: bin.1.permissive.fa bin2.orig.fa

sample3_3: bin.1.permissive.fa bin2.orig.fa

Now, I want to rename in a way that files look like this:

sample1_1: sample1_bin.1.fa sample1_bin2.fa

In other words, I the following 2 things to be changed:

  1. Include folder name in the file but after removing last part of it.
  2. Remove middle part of the file i.e. permissive, orig etc.

Any linux expert here please help me in writing the script.

Many thanks in advance!

rename loop mv

Can not install this... was able to download the tar file but can not run tar -zxvf *.tar.gz as it gives following error:

tar: brename: Cannot open: File exists
tar: Exiting with failure status due to previous errors

0 answers

No answers yet.

Log in to answer this question.