Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

Assuming i have a line that i want to add to a file without opening an editor.

How could i append this line

alias list='ls -cl --group-directories-first'

to this file
share|improve this question
up vote 95 down vote accepted

You can append a line of text to a file by using the >> operator:

echo "hello world" >> my_file.txt

or in your case

echo "alias list='ls -cl --group-directories-first'" >>

Please take note of the different types of quotes.

share|improve this answer
I use echo myself, but be careful, if you only specify one > then the file will truncate, not append. for a safer command you can use sed: sed -i '$a hello world' filename – invert Jan 25 '11 at 8:05
explanation: -i will update the file (otherwise it will just print the result to stdout), $ is regex that will match the end of the file, and a appends the following text to filename. – invert Jan 25 '11 at 8:08

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.