Combining files

Print Friendly, PDF & Email

Tag: 

You have many files in a directory that you want to combine into one file. You could open them one at a time and copy/paste them into a new file but who has time for that!

Use the cat (short for concatenate) command, with shell redirection (>>) into your output file.

First, open a shell and cd into the directory where the files reside and list the contents, for example

screenshot of bash shell listing content of directory

Next type "cat filename*.txt >> output file" and hit enter

Explanation: "cat" is the command "filename*" tells cat to concatenate all files that start with "filename" and the ">>" tells cat to output the results to a new file, and finally "output" is the name of the resultant file name.

Example screenshot:

screenshot of bash shell cat command

After running the cat command and listing the directory, you'll see the new file, in this case numbers.txt. And if you list the directory with the -al flag you'll see the file size is much larger than any single file.