Apply command to all files in a directory

6,856

You could use for loop and globbing by filename extension:

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

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

find . -maxdepth 1 -type f -iname "*.fna" -exec clustalw -infile {} -outfile {}.aln  \;
Share:
6,856

Related videos on Youtube

Manuel
Author by

Manuel

Updated on September 18, 2022

Comments

  • Manuel
    Manuel over 1 year

    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!

  • Stéphane Chazelas
    Stéphane Chazelas almost 7 years
    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.