find command to find files and concatenate them

Devesh picture Devesh · Aug 1, 2014 · Viewed 9.8k times · Source

I am trying to find all the files of type *.gz and cat them to total.gz and I think I am quite close on this.

This is the command I am using to list all *.gz

find /home/downloaded/. -maxdepth 3 -type d ( ! -name . ) -exec bash -c "ls -ltr '{}' " \

How to modify it so that it will concatenate all of them and write to ~/total.gz

Update: directory structure under downloaded is as follows

/downloaded/wllogs/303/07252014/SysteOut.gz
/downloaded/wllogs/301/07252014/SystemOut_13.gz
/downloaded/wllogs/302/07252014/SystemOut_14.gz

Answer

hek2mgl picture hek2mgl · Aug 1, 2014

Use cat in -exec and redirect output of find:

find /home/downloaded/ -type f -name '*.gz' -exec cat {} \; > output