Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find command to find files and concatenate them

Tags:

linux

find

bash

cat

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
like image 281
Devesh Avatar asked Aug 01 '14 15:08

Devesh


People also ask

Which command is used to concatenate files?

To concatenate files, we'll use the cat (short for concatenate) command.

How do you concatenate files?

To choose the merge option, click the arrow next to the Merge button and select the desired merge option. Once complete, the files are merged. If there are multiple files you want to merge at once, you can select multiple files by holding down the Ctrl and selecting each file you want to merge.

How do I concatenate files in Linux?

Type the cat command followed by the file or files you want to add to the end of an existing file. Then, type two output redirection symbols ( >> ) followed by the name of the existing file you want to add to.

What is the use of the find command?

The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments. find command can be used in a variety of conditions like you can find files by permissions, users, groups, file types, date, size, and other possible criteria.


2 Answers

Use cat in -exec and redirect output of find:

find /home/downloaded/ -type f -name '*.gz' -exec cat {} \; > output
like image 194
hek2mgl Avatar answered Nov 12 '22 20:11

hek2mgl


Use echo in -exec and redirect the output:

find /home/downloaded/ -name "*.gz" -exec echo {} \; > output 
like image 41
Ana Santana Avatar answered Nov 12 '22 22:11

Ana Santana