I want to apply the following command to all the files in the current directory

clustalw -align -infile=*here goes the input filename* -outfile=*here goes the output filename*

I also want the output filename to be the same as the input plus ".aln". For example:

clustalw -align -infile=nexus0000.fna -outfile=nexus000.fna.aln

Thanks for the help!


You could use for loop and globbing by filename extension:

for file in *.fna; do
    clustalw -align -infile="$file" -outfile="$file.aln"

If you want to use a single command, you can use find:

find . -maxdepth 1 -type f -iname "*.fna" -exec clustalw -infile {} -outfile {}.aln  \;
  • 3
    If you want the equivalent of -iname "*.fna", that would be for file in *.[fF][nN][aA] or use the extensions that some shells have for case insensitive globs. Note that find will include dotfiles though shell globs won't by default. – Stéphane Chazelas Aug 10 '17 at 20:00

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.