Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

If I have two text files, file1.txt.and file2.txt, how do I append the contents of file2.txt to file1.txt (without overwriting file1.txt) using a simple command-line?

share|improve this question

2 Answers 2

As far as I know, the simplest way would be:

cat file2.txt >> file1.txt

Reference: Appending Redirected Output.

share|improve this answer

Bash redirection would be my first choice but if you're dealing with squiffy permissions (eg the file is root-owned), I would use tee. Here's an example where we're pretending file1.txt is owned by root (or at least, isn't writable by $USER):

cat file2.txt | sudo tee -a file1.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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