# How to cat when "Argument list too long"?

**URL:** <https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348>\
**Category:** Red Hat\
**Created:** [January 8, 2021, 3:59pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348 "2021-01-08T15:59:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnaidG](https://community.unix.com/letter_avatar/anaidg/32/6_22734026db12803ebb3e059622ac3534.png) [@AnaidG](https://community.unix.com/u/AnaidG)\
**Post date:** [January 8, 2021, 3:59pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/1 "2021-01-08T15:59:31Z")

</div>

This is probably something super basic but any help would be appreciated.  
I am trying to cat a list of list ~ 203900 files into one but I get an error message of "argument list too long". I did tried to look some solutions in the web but I only found this for cp.

```
find ./ -type f -name "*.txt" -print > /tmp/files.list
cat ​/tmp/files.list | xargs -I {} cp -uf {} /path/carpet/

```

Any ideas for cat?

Thank you in advance  
Anaid

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/6_22734026db12803ebb3e059622ac3534.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [January 8, 2021, 4:13pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/2 "2021-01-08T16:13:57Z")

</div>

You need something like the following:

```nohighlight
find . -type f -name "*.txt" -exec cat {} +

```

---

<div class="post-metadata">

**Author:** ![bendingrodriguez](https://community.unix.com/user_avatar/community.unix.com/bendingrodriguez/32/21971_2.png) [@bendingrodriguez](https://community.unix.com/u/bendingrodriguez)\
**Post date:** [January 8, 2021, 4:58pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/3 "2021-01-08T16:58:28Z")

</div>

@AnaidG do you really need the list file or do you just want to copy the files?  
With the option `-n N` you can tell `xargs` that it should use a maximum of N arguments at once. Or you can use `-exec` to copy (no list file needed):

```
find -type f -name "*.txt" -exec cp -uf {} /path/carpet \;

```

---

<div class="post-metadata">

**Author:** ![AnaidG](https://community.unix.com/letter_avatar/anaidg/32/6_22734026db12803ebb3e059622ac3534.png) [@AnaidG](https://community.unix.com/u/AnaidG)\
**Post date:** [January 8, 2021, 5:24pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/4 "2021-01-08T17:24:52Z")

</div>

@bendingrodriguez I would actually like to make the cat of the files 🙂

---

<div class="post-metadata">

**Author:** ![AnaidG](https://community.unix.com/letter_avatar/anaidg/32/6_22734026db12803ebb3e059622ac3534.png) [@AnaidG](https://community.unix.com/u/AnaidG)\
**Post date:** [January 8, 2021, 5:26pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/5 "2021-01-08T17:26:58Z")

</div>

So in this case @MadeInGermany , I would just re-direct the output file, right?

```
find . -type f -name "*.txt" -exec cat {} + > file.txt

```

---

<div class="post-metadata">

**Author:** ![bendingrodriguez](https://community.unix.com/user_avatar/community.unix.com/bendingrodriguez/32/21971_2.png) [@bendingrodriguez](https://community.unix.com/u/bendingrodriguez)\
**Post date:** [January 8, 2021, 5:38pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/6 "2021-01-08T17:38:51Z")

</div>

@AnaidG the error comes from the fact that `xargs` passes all file names to `cp` at once. You should use `xargs -n N`, see above.

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/6_22734026db12803ebb3e059622ac3534.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [January 8, 2021, 6:05pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/7 "2021-01-08T18:05:51Z")

</div>

According to the initial post the **cp** was found on the Web and has no problem (xargs is smart in finding the max args), but is no solution to the **cat** problem either.

> [@AnaidG](#):
>
> just re-direct the output file, right?

Yes, but the output file itself should not be found. Name it not `.txt` or put it into a directory outside the start directory tree (e.g. ` > ../file.txt` is outside).

---

<div class="post-metadata">

**Author:** ![bendingrodriguez](https://community.unix.com/user_avatar/community.unix.com/bendingrodriguez/32/21971_2.png) [@bendingrodriguez](https://community.unix.com/u/bendingrodriguez)\
**Post date:** [January 8, 2021, 6:27pm UTC](https://community.unix.com/t/how-to-cat-when-argument-list-too-long/381348/8 "2021-01-08T18:27:10Z")

</div>

@AnaidG ah sorry, i missunderstood your question.
