How to Create, Read, Edit, and Delete Files in Ubuntu 22.04
The blog has been divided into different sections which explain:
- Creation of files on Ubuntu
- Reading of files on Ubuntu
- Editing of files on Ubuntu
- Deleting of files on Ubuntu
How to Create Files in Ubuntu 22.04
Different types of files can be created by simply using the touch command and if the files are of some specified formats then use the extensions as well, for example, a text file with the name of myFile will be created using the command:
When the command is executed successfully, list down the contents of the directory to confirm the creation of file:
In the above output, it can be seen that the file is created, now open the file using the nano text editor:
Type some text in the file:
Close the file with a shortcut key of CTRL+X after saving it with CTRL+S.
How to read Files on Ubuntu 22.04
For reading files on Ubuntu, the cat command utility can be used. For example, to read the file created in the above section, use the command:
The message of the file is 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 the files are being opened by the nano text editor:
Type some more new lines in the file:
Exit the nano text editor by saving the new change made with the shortcut key of CTRL+S and then use the cat command to view the file:
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, which is used to remove files. For example, to remove the myFile.txt, use the command:
After deleting the file, list down the contents to confirm deletion:
The file has been deleted successfully.
Conclusion
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. In this blog, an example is considered to explain the commands for the creation, reading, editing, and deleting of the files in Ubuntu 22.04.