49

I want to cat a file in current folder and all files in all subfolders (and subsubfolders).

Here is my directory structure

$ tree
.
├── f
│   └── foo
└── yo

I want to cat foo and yo.

I've tried this command but did not work:

cat */*

It just cats foo.

2

2 Answers 2

56

try:

   find . -type f -exec cat {} +
3
22

cat accepts multiple arguments, so you can:

  cat * */*

to cat everything in the current directory and in all subdirectories. You can also

  cat * */* */*/*

and so on, if you want.

Note, of course, that your shell is translating those '*'s into a list of files then passing that whole list to cat.

3
  • 1
    With shopt -s globstar enabled on bash 4+, you can use cat ** instead of the second one.
    – evilsoup
    May 25, 2013 at 11:07
  • 3
    That's not a useful solution, as you need to know how many layers deep to go. Oct 25, 2016 at 15:06
  • Moreover, the directories will be processed
    – Rémi B.
    Nov 22, 2018 at 18:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.