What if files are in subdirectories?

091

If you want to concatenate files located in subdirectories as well, you can use the find command in combination with cat. Here's how you can do it:

find /path/to/directory -type f -exec cat {} + > combined.txt

In this command:

  • Replace /path/to/directory with the path to your main directory.
  • -type f ensures that only files are selected.
  • -exec cat {} + executes the cat command on all found files.
  • combined.txt is the output file that will contain the concatenated contents of all files found in the directory and its subdirectories.

If you want to concatenate only specific types of files (e.g., all .txt files), you can modify the command like this:

find /path/to/directory -type f -name "*.txt" -exec cat {} + > combined.txt

This will concatenate all .txt files in the specified directory and all its subdirectories into combined.txt.

0 Comments

no data
Be the first to share your comment!