Linux – Renaming files without file extensions

linuxrename

I have a series of files named KLLxxx (the x represents numbers). They're text files but have no file extension to them. Just files that say KLL followed by three digits. I want them all to end with the file extension .fastq. Such as KLL123 -> KLL123.fastq.

So I tried using this command

mv KLL* KLL*.fastq

But I keep on getting the error message:

mv: target 'KLL067.fastq' is not a directory

I know about the rename command function, but I've never used Perl before so I don't know how to approach this. I know this is a basic question, but this is my first time trying out Linux.

Best Answer

Running the following find command in the directory you are looking at will do the trick:

find . -name 'KLL[0-9][0-9][0-9]' -exec sh -c 'mv $0 $0.fastq' {} \;

Which will add the extension .fastq to any file name starting with KLL followed by three digits.

Related Question