How to Add Text to a File in Linux Via the Command Line

Save

From the point of view of the Linux operating system, all files are just sequences of bytes; Linux does not make any distinction between files containing human-readable text, encoded database tables or executable machine code. The Linux command line, also known as shell, has powerful mechanisms to add contents to a file. In particular, you can append additional text to a Linux file from the command line.

  • Log in to the computer.

  • Launch a shell, by either logging in to text mode or by launching a Terminal window from the graphical desktop.

  • Type the following command into the shell:

    echo "new text" >> /home/fangulo/textFile.txt

    Replace "new text" by the text you want to add to the file, and replace "/home/fangulo/textFile.txt" by the name, with the full path, of the file to which you want to add the text. Press "Enter." When the shell prompts you for a new command, the text will have been added to the file.

References

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images
Promoted By Zergnet

Comments

You May Also Like

Related Searches

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!