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:
If the command ran successfully, list the contents of the directory to confirm the file was created:
The above output shows that the file has been created. Now open the file with Nano text editor:
Enter text in the file:
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:
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:
Enter more new lines in the file:
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:
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:
After deleting the file, list the contents to confirm the deletion:
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.