find command to find files and concatenate them
11,839
Solution 1
Use cat
in -exec
and redirect output of find
:
find /home/downloaded/ -type f -name '*.gz' -exec cat {} \; > output
Solution 2
Use echo
in -exec
and redirect the output:
find /home/downloaded/ -name "*.gz" -exec echo {} \; > output
Author by
Devesh
I always believe that learning is a lifelong process and have realized that reading and answering SO questions, I have learned lot of things. That's why I am here.
Updated on June 13, 2022Comments
-
Devesh almost 2 years
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
-
Devesh over 9 yearsIt did not work, it says downloaded/./wllogs/301/07172014 : Is a directory . Did I miss anything in ques?
-
hek2mgl over 9 yearsI would expect
-type f
(Didn't realized that you used -type d) -
Devesh over 9 yearsI tried with f but the output file size is zero. so it did not work either.
-
Devesh over 9 yearsNo luck this time too. Just a observation - When I tried with -type d and ls command it did show all the directories and files. and with type f nothing comes up
-
Devesh over 9 years@ hek2mgl : Awesome, I tried with maxdepth 4 and it did show files. IT worked ! Thank you for time
-
hek2mgl over 9 years
-maxdepth 4
would have been the next thing that I would have suggested. (As the path to tgz'S contains 4 and not 3 components). However, if there aren't gzips located in folders nested deeper than 4, I would just skip. (this would speedup the find process) -
Devesh over 9 yearsYes, This indeed speed up,
-
Mohan Kumar P over 7 yearsfind . -name *.gz > /tmp/1.txt This command gave me the expected output