Search code examples
ubuntuunixbioinformatics

How to select files in subdirectories by name and move all files containing "XXX" and "YYY" into new directories


Directory contents

Subdirectory contents

Hello all, how can I move all files with the name "ATAC" and all files with the name "RNA" into separate folders? The context is that in the current the directory, I have many subdirectories which contains fastq files with "ATAC" and "RNA" in their names; if the files were in the directory in not stored in another directory, it would be easy and I can just select the files using RNA* and ATAC*, but the problem is they are stored in subdirectories; how can I select the 2 subset of files and move them into new separate (one for ATAC, one for RNA) folders in this case?


Solution

  • With the command find (https://linuxize.com/post/how-to-find-files-in-linux-using-the-command-line/), you can look for a file in every directory and subdirectory and execute a command on it.

    find -L . -name "*ATAC*" -exec mv {} path-to-your-directory/ \