mv
either takes a single file and moves or renames it, or it takes a number of files or directories and moves them to a directory. You can't rename multiple files with mv
.
Instead:
for name in *.*.fasta.gz; do
newname=${name%.fasta.gz} # remove filename suffix
newname=${newname//./_}.fasta.gz # replace dots with underscores and add suffix
mv -i -- "$name" "$newname"
done
This would iterate over all your compressed fasta files in the current directory that contains at least one dot elsewhere in the name, apart from in the filename suffix. It would remove the known filename suffix (which should not have dots replaced by underscores) and then substitutes all dots with underscores in the remaining bit and re-attaches the suffix.
The final substitution will work in the bash
shell, but possibly not if running under /bin/sh
.
mv -i
is then used to rename the file (will ask for confirmation if the new name already exists). The double dash (--
) is used just in case any of the names start with a dash (these would potentially be taken as sets of options to mv
and the double dash prevents this).
x_assembled_forward.fastq.gz
still has.
in it. Did you meanx_assembled_forward_fastq_gz
? – muru Aug 05 '19 at 08:05.
with_
. The last two, however, shouldn't be changed so the answers of the dupe don't really apply. – terdon Aug 06 '19 at 08:14