Saturday, November 14, 2015

How to execute multiple unix commands within find -exec command

In a previous post you could find a solution how to pipe multiple commands within unix find -exec command.

If you need to execute multiple commands without piping them, you can call -exec multiple times within a find command.

This commands will first invoke shell and run ls -lh, then run echo and list the name of the file.

sudo find ./  -iname '*fastq.gz' -exec sh -c "ls -lh {}" \; -exec echo {} \;

-rw-rw-r-- 1 clint clint 23G Jan 26  2015 ./1410UNHS-0007/2102/141107_H0E37_2102_L002_R1.fastq.gz
./1410UNHS-0007/2102/141107_H0E37_2102_L002_R1.fastq.gz
-rw-rw-r-- 1 clint clint 24G Jan 26  2015 ./1410UNHS-0007/2102/141107_H0E37_2102_L002_R2.fastq.gz
./1410UNHS-0007/2102/141107_H0E37_2102_L002_R2.fastq.gz
-rw-rw-r-- 1 clint clint 30G Jan 26  2015 ./1410UNHS-0007/2102/141125_H22TJ_2102_L002_R2.fastq.gz
./1410UNHS-0007/2102/141125_H22TJ_2102_L002_R2.fastq.gz
-rw-rw-r-- 1 clint clint 28G Jan 26  2015 ./1410UNHS-0007/2102/141125_H22TJ_2102_L002_R1.fastq.gz
./1410UNHS-0007/2102/141125_H22TJ_2102_L002_R1.fastq.gz
-rw-rw-r-- 1 clint clint 40G Jan 26  2015 ./1410UNHS-0007/1448_1/141125_H22TC_1448_1_L007_R1.fastq.gz
./1410UNHS-0007/1448_1/141125_H22TC_1448_1_L007_R1.fastq.gz
-rw-rw-r-- 1 clint clint 41G Jan 26  2015 ./1410UNHS-0007/1448_1/141125_H22TC_1448_1_L007_R2.fastq.gz
./1410UNHS-0007/1448_1/141125_H22TC_1448_1_L007_R2.fastq.gz
-rw-rw-r-- 1 clint clint 36G Jan 26  2015 ./1410UNHS-0007/2228_1/141125_H22TJ_2228_1_L004_R2.fastq.gz
./1410UNHS-0007/2228_1/141125_H22TJ_2228_1_L004_R2.fastq.gz
-rw-rw-r-- 1 clint clint 32G Jan 26  2015 ./1410UNHS-0007/2228_1/141125_H22TJ_2228_1_L004_R1.fastq.gz
./1410UNHS-0007/2228_1/141125_H22TJ_2228_1_L004_R1.fastq.gz
...

No comments:

Post a Comment