How to create a new text file in Linux?
Published on Aug. 22, 2023, 12:17 p.m.
To create a new text file in Linux, there are several ways you can do it using the command line. Here are a few examples:
- Using the
touch
command:
touch filename.txt
This will create a new empty file called filename.txt
in the current directory.
2. Using the echo
command and redirecting output to a file:
echo "this is some text" > filename.txt
This will create a file called filename.txt
with the text “this is some text” in the current directory.
3. Using a text editor such as nano
or vim
:
nano filename.txt
This will open the nano
text editor, where you can create and edit a new file called filename.txt
.
4. Using the cat
command and redirecting input to a file:
cat > filename.txt
This will let you type in the contents of the file manually. Press CTRL + D
when you are done to save the file.
Note that in all cases, the file will be created in the current working directory unless you specify a different path.