How to Upload a Txt File in Linux
There are a couple of quick ways to create a text file from the Linux Command Line or Terminal. Some of them take been explained in the following article.
1) touch command
This is the most standard control to quickly create an empty text file. The command is quite simple to type and makes it quite easier to create several text files at once. The commands are as follows:
touch filename.txt
As simple as that, only type the give-and-take touch followed by the name of the file you like to give information technology, and Voila! you accept created an empty text file inside of a concluding. You can add together the file names of the file you would similar to create at once with infinite in between each filename. The command below creates 3 empty files at once using the impact control and you can create equally many files as yous like.
bear upon file1.txt file2.txt file3.txt
touch command
bear on command for creating multiple files
2) Standard Redirect Symbol(>)
It is as well quite piece of cake to empathise the command to create a text file in the final with the minimum effort. This works really very well for creating a single text file speedily, but for creating several text files at one time it becomes a bit dull. The control is but using the standard redirect symbol (>) spacebar followed by the file name.
> filename.txt
If you want to create several text files at one time, then you tin add the redirect symbol after the previous filename and concatenation the control repeatedly to create multiple empty files.
> file.txt > file2.txt > file3.txt
The above control creates three empty text files. The redirect symbol is quite time-saving if you just desire to create a single text file. Information technology gets quite longer than the bear upon command to create multiple empty text files.
Using the redirect symbol for creating files.
three) CAT Command
At present, this method is besides quite simple and piece of cake to use. Simply type in Cat with 2 redirect symbols (>>) and the file name( It is non mandatory to use >> symbols, a user tin can also utilise > symbol, only if the user types a pre-existing file by mistake, the existing content in the text file will be overwritten using a single > symbol). This method is a kind of combination of touch and the redirect symbol commands. This method is a bit quirky, so you only prefer using the above ii commands if y'all want to create an empty never edited file. If you want to create and type in the text file straight abroad, by far this is quite a brilliant method. This will salve you fourth dimension to open up upward an editor and the command is also quite piece of cake.
The below command creates an empty even so edited file equally it prompts the user to create a text file and type in the file at the aforementioned time. So, if yous practise not want to edit the file, just press CTRL+C and information technology volition simply exit and create an empty file.
true cat >> file.txt
But, if you would like to add together some text to the file, yous can type in later on this, similar this:
true cat >> new.txt This is some text in the file from control line.
To terminate editing and saving in the file, but type CTRL+C, information technology volition create, save and exit the file. So, this method is quite a time-saving method if yous desire to edit the text file very quickly. The following command will suspend the text to the pre-existing file. On the other hand, if you lot utilize a unmarried redirect symbol(>) it will overwrite the content of the file, so you simply adopt using double redirect symbols for safety reasons.
Using cat command to create the file.
Using cat command to create and write a file.
four) Using echo / printf
This is also like to true cat command, but it is very flexible comparatively. The post-obit control is ordinarily used for press text on the terminal, but we can besides use it to write to a file or brand an empty file. The echo command is used forth with the double redirect symbols (single > volition likewise work) followed by the filename.
echo >> filename.txt
If y'all want to create multiple files at a fourth dimension, you can chain upward the control as in previous methods.
repeat >> file1.txt >> file2.txt >> file3.txt
We tin can also add functionality to the echo control to speedily create and write to the text file but like cat control.
echo -eastward 'This will be the text in the file \n this is the new line' >> file.txt
The in a higher place control can exist highly customizable as it uses the properties of the echo control to brand it quite versatile to write the text in the file, but using a new line character every time tin be annoying every bit well.
using the echo command to create files.
Using echo command to create and write to a file.
Like to the echo control, nosotros accept the printf command besides. The print command does the same thing equally the echo control but in a C style rather than shell-manner editing.
printf "" >> filename.txt
printf "" >> file1.txt >> file2.txt >> file3.txt
printf "This is some text here \n The 2nd line \n The third line" >> file.txt
The print command does some pretty C-like things, such as the newline character and the variable names can be used also, but that is not for a simple text file. Just still, the printf command can be useful in a lot of cases to edit files on the go.
Using printf command to create files.
Using printf to create and write to files.
5) Any command-line text editor(Vim, nano)
This is the most fourth dimension-consuming method and non the fastest, yet the method can be useful for Linux beginners. If you want to heavily edit a text file, y'all can utilize command-line text-editors such as Vim, nano, and at that place are other options too. But most people use nano every bit it is simple to apply and quick to go. Vim can also exist used but almost beginners find it difficult to use, and so we'll stick with nano for this example.
nano filename.txt
vim filename.txt
We are now in the nano editor(or vim). You can blazon in the stuff you lot require and simply type CTRL+Due south to save and CTRL+Ten to exit. In Vim it is a bit unlike. We won't brand a vim guide here, so you can check out the 'Nano text editor in Linux' or 'Getting started with vim' commodity from geeks for geeks.
Using Nano to create and write files.
And then that wraps up the methods for apace creating a text file or writing to the file. Each method can exist used differently depending on the situation and the case used. Not every method will be the fastest, yet these were some of the fastest means to create a Text File Using the Control Line in Linux.
Source: https://www.geeksforgeeks.org/how-to-create-a-text-file-using-the-command-line-in-linux/
Post a Comment for "How to Upload a Txt File in Linux"