Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

up vote 46 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'" >> config.fish

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.