3 ways to create a new blank file in linux

Using the Linux command line or the bash shell, how can I create a blank file? I need to know the Linux command to create a new, blank file.

A zero-byte text file is an empty file. In the terminal, there are many ways to generate a new, blank file.

1. Use the touch command to create a blank file

In Linux, you can use the touch command to make a blank file. The touch command generates a file that contains zero bytes because it is empty. When making a new file, if the user doesn’t yet have any information to save, they can use this command. The touch command in Linux can also be used to alter a file’s timestamp.

Syntax:

touch filename

Example:

touch myfile.txt

2,cat command

Simply put, it is the go-to command or tool on Linux systems for making new files. A file cannot be modified with the cat command. Here are some of the more substantial tasks that can be accomplished with it:

To create files and write the data into them

cat >file1

If the file file1 does not already exist in the current working directory, this command will create it. In the event that a file called file1 already exists in the current directory, it will be replaced.

Please remember to hit ctrl+d when you have finished typing in the file in order to save your work and leave the editing window.

3,vi command

Its primary use is for modifying existing files. The vi text editor is widely used by programmers for modifying the text of any file. Here are some of the more substantial tasks that may be accomplished with it:

It is important to remember to press the Escape key and then type:wq before exiting the vi text editor.

Create a file

vi file_1

If file 1 does not exist in the current working directory, this command will create it and open it in the vi text editor. This command merely launches the vi text editor and loads the file with the name file 1 if it is present in the current working directory.

What is the purpose of the touch command on Linux?

Apply the current Linux time to the access and modification timestamps of the specified FILENAME with the touch command. If FILENAME doesn’t already exist, a new, blank file will be made with that name. On Linux, the following file command will show if the file is empty:

file passbook.txt

passbook.txt: empty

How do you create multiple blank files in Linux?

We’ll start with the touch command, which will show you how to make multiple files at once, and then move on to the for loop, which will show you how to make multiple files sequentially.

Creating Multiple Files at once using touch Command

With the touch command, which is standard fare on any Linux installation, you can quickly and easily create multiple files without worrying about their names until after you’ve done so.

Then, to generate a batch of files with a single command, you need only use the syntax shown below.

$ touch filename{1..N}

The syntax is straightforward: just specify the name of the file you want to make, and use Brace expansion to define the range of numbers you want to save between.

Because running the above command will create multiple files, which can mess up your current directory structure, let me first create a directory where we can learn how to use the above command, and I even suggest you do the same.

$ mkdir createmultiplefile

$ cd createmultiplefile

Once you’re in the ‘createmultiplefile’ folder, use the command below to generate 10 new single-file directories.

$ touch filename{1..10}

You learned that an empty file is a file that contains no data and got zero bytes in size. Further, you used the touch command to create an empty file on the Linux operating system.

You now know that a file with no data and a size of 0 bytes is called an empty file. In addition, you used 3 ways to make a new, empty file.

Categories

Leave a Reply

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