How to Create a New File Using Terminal

Previously we have learned how to create a new directory using command line interface or by using Terminal on Linux using the command mkdir.

Meanwhile, to create a file, Linux provides a special command that we can use, namely the command touch. Create a file using the command touch quite easy, the method is almost the same as how to create a folder.

Order touch can be used to create files with any extension you want, you only need to add the extension name of the file after the file name.

Creating Files Using Touch Commands

For example, you want to create a file that has the format “.txt” with the name “text”, you can do this by using a command like the following:

touch teks.txt

To prove whether the file was created successfully, you can check it by using the command ls.

ls

Then the file that you created earlier will appear as shown below:

Creating Files Using Terminal
Creating Files Using Terminal

This means that you have successfully created a file using the command touch.

Creating a New File in a Specific Folder

In addition to creating a file directly in the directory where you are currently, you can also create a file instead of a folder or a directory structure with referencejust as you can do with the command mkdir, order CDand command ls previously.

For example, in the directory you are currently in, there is a folder called “folder1”, you can create a new file in “folder1” without first entering the folder.

For example, you will create a file with the extension named “header.php” in “folder1”, then you can create it using the command:

touch folder1/header.php

To check whether the file has been successfully created in “folder1”, you can check it by using the “ls” command as follows:

ls folder1

Then you will see a file named “header.php” in “folder1” as shown below:

Creating Files in Folders Using Terminal
Creating Files in Folders Using Terminal

It means that you have successfully created a file in a folder or by using the reference method.

Enough of the tutorial this time on how to create a file using command line interface.

Previously we also learned about how to create a folder, next we will learn how to delete a folder and a file in Terminal using command line interfaces.

For those of you who want to learn a lot of complete subject matter, we also recommend trying to access the ruangguru.co.id site for learning exercises there.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *