Category: Linux Terminal
Added: 11th of May 2023
Updated On: 19th of April 2024
Viewed: 909 times
This article was updated and rechecked on 19th of April 2024
Write and append to .txt file using the terminal in Linux
To write and append to a .txt file using the terminal in Linux, first create a new textfile on your desktop using the touch command
cd Desktop
touch sample_file.txt
To write to the text file we use the
echo command followed by
> then the filename you want to write to
echo "My favourite Linux Distros are" >> sample_file.txt
To append / add to the text file we use the
echo command again followed by
>> then the filename you want to write to
echo "Kubuntu" >> sample_file.txt
echo "Lubuntu" >> sample_file.txt
echo "Xubuntu" >> sample_file.txt
echo "Mint" >> sample_file.txt
To view the file in the terminal we use the cat command
cat sample_file.txt