To create a file in Linux is easier than eating ice-cream. Yes, I am talking about creating a file in the windows operating system is quite simple and easy.
But to create a file in Linux is easier than creating a file in the Windows operating system, and you have multiple options to complete this task If you are using Linux.
If you think it is not true, then continue reading..
In this article, I am going to cover multiple ways to create a file in the Linux operating system. All methods have an appropriate example, so you can understand better.
I cover the following methods for creating a file in Linux step by step, you can jump on a particular section by clicking on the link.
Article Contents
- Create an empty file in Linux using the Touch command
- Create a File in Linux using Cat command
- Create a File in Linux using nano command
- Create a File in Linux using Vi or Vim editor
- Create a File in Linux using Text Editor – Graphical interface
- Conclusion
Create an empty file in Linux using the Touch command
What are you thinking? Is it “Why is an empty file?”
It may have multiple reasons to create an empty file. You may create an empty file just for fun or you want to create multiple files without content.
Maybe you are an administrator and your boss have need of some files, then create blank files. Why will you fill the content? if it is not required.
There are so many reasons to create a blank file in Linux.
Use the touch command followed by file name and path.
$touch /path/to/location/filename.txt
If you want to create a blank file in the present working directory then give the filename only after touch command.
$touch filename.txt
vijay@Ubuntu-19:~/Documents$touch firstfile.txt vijay@Ubuntu-19:~/Documents$ls -l total 0 -rw-r--r-- 1 vijay vijay 0 Jun 16 17:39 firstfile.txt vijay@Ubuntu-19:~/Documents$
vijay@Ubuntu-19:~/Documents$touch /home/vijay/Downloads/file_2.txt vijay@Ubuntu-19:~/Documents$ls /home/vijay/Downloads/ file_2.txt vijay@Ubuntu-19:~/Documents$
You can create multiple empty files by using the single command
$touch file1 file2 file3 file4
vijay@Ubuntu-19:~/Documents$touch file.txt file1.txt file2.txt file3.txt vijay@Ubuntu-19:~/Documents$ls file1.txt file2.txt file3.txt file.txt firstfile.txt vijay@Ubuntu-19:~/Documents$
You can play with touch command and empty files, you can fill the content by using cat command, vi editor or text editor. It is up to you.
Also Read: How to use touch command in Linux
Create a File in Linux using Cat command
Cat command is a very useful command for Linux users. You can put yourself inside Linux users because you have taken a move. You have started to learn Linux.
Cat command can be used:
- Create a new empty/data file.
- Add content inside exist file.
- Overwrite a file
- View the content inside file.
Here I am going to tell you how to create a file in Linux by using cat command. use cat > followed by path and file name.
Complete tutorial of cat command in Linux
vijay@Ubuntu-19:~/Documents$cat >newfile.txt Write first line and hit enter write second line and hit enter when you have completed you writing press Ctrl+D to save file vijay@Ubuntu-19:~/Documents$cat >>newfile.txt Add new line and hit enter add another line and hit enter press Ctrl+D to save data vijay@Ubuntu-19:~/Documents$cat newfile.txt Write first line and hit enter write second line and hit enter when you have completed you writing press Ctrl+D to save file Add new line and hit enter add another line and hit enter press Ctrl+D to save data vijay@Ubuntu-19:~/Documents$
Create a File in Linux using nano command
nano is another utility comes by default with most Linux distribution.
I am using Ubuntu 19.04 at the time of writing this article. So nano is preinstalled in Ubuntu 19.04. This is good news for me.
nano command is used to create a new file, edit existed file, and view the file content. You can use official documentation to learn more nano editors and short cuts for here nano-editor
nano filename is used to see the content and edit the file. the given filename doesn’t exist, nano will create a new file.
$nano newfilename.txt
vijay@Ubuntu-19:~/Documents$nano file10.txt vijay@Ubuntu-19:~/Documents$Add first line and hit enter add secont line and hit enter add multiple lines without any problem ^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^C Cur Pos ^X Exit ^R Read File ^\ Replace ^U Uncut Text^T To Spell ^_ Go To Line vijay@Ubuntu-19:~/Documents$
Press ^X means (Ctrl+x) to exit the file. Press Y if you want to save file No for quitting without saving the content. If you have pressed Ctrl+X by mistake so press Ctrl+c to cancel the process
Create a File in Linux using Vi editor
Vi or vim is one of the most popular text file editors in Linux world. It can be used to write a big file, long code files. Most Linux code developer love this editor.
vi is short for the visual editor.
I can’t cover all the feature in this article, Because it has three modes and multiple shortcuts and commands inside single utility.
Here is the book for vim /vi editor. It has 572 pages only. Download vim book
To start using vi, at the Unix prompt type vi followed by a file name. If you wish to edit an existing file, type in its name; if you are creating a new file, type in the name you wish to give to the new file.
$vi filename
Then hit Return. You will see a screen similar to the one below which shows blank lines with tildes and the name and status of the file.
~
~
“myfile” [New file]
vijay@Ubuntu-19:~/Documents$vi newfile1.txt
press I before wirte anything, then start writing whatever you want , but I suggest you read something before start using vi editor ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Press Esc then: wq to write and quit from vi editor.
Create a File in Linux using Text Editor – Graphical interface
Do you love GUI (Graphic User Interface)? This section is only for you.
You can create a file in Linux by using GUI. Simply follow the given steps:
Step 1:

Step 2:

Step 3:

Step 4:

Conclusion
In this article, I have covered 5 ways to create a file in Linux 4 ways belongs to command-line interface another is the graphical interface. So now you have learned lots of things through this article.
If you have any question please leave in the comment box.