Activate the "New Document" option with specific file extensions in Ubuntu 22.04

Software Engineer@Datasoft Systems Bangladesh Limited BSc. in CSE
Here's how you can do it:
Open a terminal by pressing
Ctrl + Alt + Tor searching for "Terminal" in the application launcher.Navigate to your templates directory by running the following command:
cd ~/TemplatesCreate blank files with the desired file extensions. Run the following commands to create the required files:
touch New Text Document.txt touch New Presentation Document.odp touch New Word Document.docx touch New Excel Document.xlsx touch New CSV Document.csvNow, we'll create a script that allows you to create new files with these extensions from the right-click menu.
Run the following command to create the script file:
touch create_new_document.shOpen the script file using a text editor:
nano create_new_document.shAdd the following lines to the script:
#!/bin/bash file_ext="" case "$1" in "Text file") file_ext=".txt";; "Presentation file") file_ext=".odp";; "Word file") file_ext=".docx";; "Excel file") file_ext=".xlsx";; "CSV file") file_ext=".csv";; *) exit 1;; esac touch "${2}/${file_ext}"Save the file by pressing
Ctrl + O, and then exit the text editor by pressingCtrl + X.Make the script executable by running the following command:
chmod +x create_new_document.shNext, we need to create a
create_new_document.desktopfile to add the script to the right-click menu.Run the following command to create the
create_new_document.desktopfile:touch create_new_document.desktopOpen the
create_new_document.desktopfile using a text editor:nano create_new_document.desktopAdd the following lines to the file:
[Desktop Entry] Name=Create New Document Exec=/path/to/create_new_document.sh "%M" "%f" Icon=document-new Type=Action Categories=FileManagerActions; MimeTypes=inode/directory;Make sure to replace
/path/to/create_new_document.shwith the actual path to thecreate_new_document.shscript file you created earlier.Save the file by pressing
Ctrl + O, and then exit the text editor by pressingCtrl + X.Move the
.desktopfile to the~/.local/share/file-manager/actionsdirectory by running the following command:mkdir -p ~/.local/share/file-manager/actions mv create_new_document.desktop ~/.local/share/file-manager/actions/Finally, restart the file manager for the changes to take effect. You can do this by logging out and logging back in, or by running the following command:
nautilus -q
After completing these steps, you should see the "Create New Document" option with the specified file extensions when you right-click in any folder. Selecting the option will create a new file with the appropriate extension in the current directory.



