How to Append Text to End of File in Linux

User Avatar
👤 admin
🔴 Admin
✍️ The most important thing in the world is to not be alone.
⏳ Last active: 15 Apr 2025 at 16:01
📅 Created: 17 Apr 2021 at 05:06
👀 Viewed: 20 times
✉️ Send Email

How do I append text to end of file using the cli on Linux? How to add lines to end of file? How to Linux logs work?! What command I need to type to send the output of the command to end of file?!
You need to use the ">>" to append text to end of file. It is also useful to redirect and append/add line to end of file on Linux or Unix-like system.

Append Text Using >> Operator

Using >> you add a new line of specific text to your text file.


# Append a row in a text file 
echo "Lateweb.info is one hell of a good site" >> filename.txt

or

printf "If you like us please subscribe for our youtube channel" >> filename.txt

You can also use the cat command to link text from one or more files and add it to another file.


cat /var/log/auth.log >> filename.txt

As you may have guessed, you can use different commands to insert values into additional rows. Another such example is the ls command to list files and folders.


# Add a list of files and folder to filename.txt

ls >> files.txt

the difference between> and >> is that one > overwrites a line and two >> adds a new line. To avoid mistakes, always check carefully how many characters you have written when writing> and >>

Difference between > and >>

Typically ```

>


Typically ```

>>

``` is used for items such as logging events, parsing or other data processing where data is created or transformed piece by piece into a new form

Both commands redirect output of command to file  ```

list

```. ```

>
``` will create/replace the output file with name ```

list

```. ```

>>

``` will create (if file ```

list

``` not exists already) or append the file ```

list

```. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>

<strong>Examples:</strong><br>```

$ ls &gt; allmyfiles.txt

```&nbsp;creates the file "allmyfiles.txt" and fills it with the directory listing from the ls command

$ echo "End of directory listing" >> allmyfiles.txt

$ > newzerobytefile



Quick video on the topic

https://youtu.be/GPAL-XU4BA4

We hope you enjoyed this&nbsp;<a href="https://lateweb.info/category/linux/">article</a>. if that is so please rate this page with the stars bellow and subscribe to our&nbsp;<a href="https://www.youtube.com/channel/UCh7Q9uaAt5-Z2lCZXX3OsvQ">YouTube channel</a>.
If you want to comment: Login or Register