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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.