in

LinuxLinux

How To Create A File In Linux {Ubuntu 18.04 & 19.04}

Different ways to create a file in Linux Ubuntu!

Create a File using Touch

C

reate a File in Linux: Creating a new file in Linux & Ubuntu can be done through the two methods, one is through the Commands & another one is through the desktop file manager. There are many ways to create a file or multiple files using the commands in Terminal. In this article, you will know the different ways to create a file using Linux commands.

Jump To:

How to create a file in Linux using Touch Command:

The touch command will help you create a new file in the Linux. The touch command will help you create the new file, multiple files & update the timestamp of your file in Linux. Use the following command to create the new file using touch command.

$touch file.txt

Command explanation: 

  • touch– Helps you create the new file
  • file– The name of the file that you want to create
  • .txt– Extension of the file that you want to create

How to create multiple files using touch command:

It is possible to create multiple files using the touch command, use the following command to create multiple files in Linux.

$touch file_name1.txt file_name2.txt file_name3.txt

The above command will help you create the multiple files in Linux.

Check this too  How to Change User Password in Ubuntu 18.04 LTS & 19.04 Disco Dingo

How to create a file in Linux using Redirection Operator:

The Redirection command will help you create a file in Linux. This command which captures the output from any command and will send to the new file. The >, help you overwrite the file and >>, help you append the new file in Linux. Follow the command will help you create the new file in Linux.

$> file1.txt

Note: You need to use the command very carefully because The above command will override the existing file.

How to create a file in Linux using CAT Command:

Basically, CAT command is mainly used to concatenate & read the existing files. This CAT Command can also be used to create a new file in Linux. With the help of the Redirection operator, The CAT command will help you create a new file. Use the following command:

$cat > file.txt

Command Explanation:

  • cat– Helps you create the new file.
  • file– The name of the file that you want to create.
  • .txt– Extension of the file that you want to create.

How to create a file in Linux using ECHO Command:

The ECHO command is mainly used to print values in Linux. You can pass the arguments & values using the echo command along with the redirection operator. Use the following command to do.

$echo > file.txt

The above command will help you create a new file. If you want to pass the values & arguments on the new file and then follow the below command:

$echo "Sample Text" > file.txt
  • echo– Helps you print the new file.
  • sample text– Sample arguments passed to the new file.
  • file– The name of the file that you want to create.
  • .txt– Extension of the file that you want to create.
Check this too  How to Find IP Address in Linux?

How to create a file in Linux using Herodoc Command:

The Herodoc command or Here Document will help you to pass the multiple values or arguments to the file. Use the following command to do.

$<< ABC > file1.txt
Sample Text
Another Sample Text
ABC

You can add any variables, special characters & commands. In this way, Herodoc command is used to create a new file in Linux.

How to create a Big File in Linux using DD & flocate Command:

It is possible to create a big file in Linux. It can be done through the DD command & flocate command in Linux.

Create a Big File using DD command:

For Example, If you want to create a new file 5G.txt with a size of 5GB in your PC & then use the following command.

$dd if=/dev/test of=5G.txt bs=1 count=0 seek=5G

Create a Big File using flocate command:

For Example, If you want to create a new file 5G.txt with a size of 5GB in your PC & then use the following command.

$fallocate -l 5G 5G.txt

The above command will help you create a big file using flocate command.

Verdict:

That’s it, you have learned a few commands to create a new file in Linux. If you have any queries related to this topic and feel free to comment on us.

Article Review
  • Article Explanation
  • Images Explanation
  • Commands Provided
  • Alternate Ways
4.9

Summary

For more article, Kindly visit our Homepage

Sending
User Rating 5 (1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by Julian

Hello Folks! I'm Julian, Promoted to the Content writer for the category of Commands & Web Apps in Tec Robust. Enjoy my content & Learn more Linux Commands!

Contact me:
tecrobust [@] gmail.com
Sub: Message to Julian

Set Static IP Ubuntu

{Latest} Configure Static IP Address On Ubuntu 18.04 LTS- How To?

Install Chromium Linux Ubuntu

Chromium Linux- How to Install Chromium on Linux Ubuntu 18.04.2 LTS, 19.04 & More