How to create, read, edit and delete files in Ubuntu 22.04

In Ubuntu, since Ubuntu is known to be manageable through the terminal, we can create different types of files by executing some simple commands. This blog will discover some simple commands to create, edit, read and delete different types of files.

How to create, read, edit and delete files in Ubuntu 22.04

The blog has been divided into different sections that explain:

How to create files in Ubuntu 22.04

Different file types can be easily created with the touch command and if the files have certain formats use the extensions as well, for example a text file named myFile is created with the command:

$ touch myfile.txt

If the command ran successfully, list the contents of the directory to confirm the file was created:

$ ls

The above output shows that the file has been created. Now open the file with Nano text editor:

$ nano myfile.txt

Enter text in the file:

Welcome to LinuxHint

Close the file with a keyboard shortcut of CTRL+X after saving with CTRL+S.

How to read files on Ubuntu 22.04

The cat command utility can be used to read files on Ubuntu. For example, to read the file created in the section above, use the command:

$ Cat myfile.txt

The message of the file will be displayed on the screen.

How to edit files on Ubuntu 22.04

To edit the already created files, open them with some text editors like Vim and Nano, here Nano text editor will open the files:

$ nano myfile.txt

Enter more new lines in the file:

This is a tutorial on how to create, view, edit and view the files on Ubuntu

Exit the nano text editor by saving the new change with the keyboard shortcut of CTRL+S and then use the cat command to view the file:

$ Cat myfile.txt

The edited changes can be read in the above output.

How to delete the files in Ubuntu 22.04

To delete the files in Ubuntu, use the rm command with the “-f” flag used to remove files. For example, to remove myFile.txt use the command:

$ rm -f myfile.txt

After deleting the file, list the contents to confirm the deletion:

$ ls

The file was successfully deleted.


The touch command is used to create files, the cat command to read files, the nano text editor to edit files, and the rm command to delete files on Ubuntu 22.04. This blog will consider an example to explain the commands to create, read, edit and delete the files in Ubuntu 22.04.

Related Posts