write a script for ubuntu that will create a text file on double click
- User
write a script for ubuntu that will create a text file on double click
- Assistant
To create a script that will create a text file on double click in Ubuntu, follow these steps:
-
First, open a text editor like Gedit, and create a new empty file.
-
Paste the following code into the text editor:
#!/bin/bash # A script to create a new text file on double click in Ubuntu # Get the current date and time to use as a part of the filename timestamp=$(date +"%Y%m%d_%H%M%S") # Set the filename with the timestamp filename="new_file_$timestamp.txt" # Create the file in the current directory touch "$filename" # Open the file with your preferred text editor (like Gedit, Nano or Vim) gedit "$filename" & exit 0-
Save the file with a meaningful name like "create_text_file.sh".
-
Open the terminal and change the current directory to the location where you saved the script file.
-
Run the following command to make the script executable:
chmod +x create_text_file.sh-
Now you can double click on the "create_text_file.sh" file in the file manager.
-
In the "Open With" dialog, choose "Run" or "Run in Terminal" (the file should be set to run with "bash" by default).
-
The script will create a text file with a unique timestamp in its name in the same directory where the script is located and open it with the text editor (in this case, Gedit).
Note: If you want to create the .sh file without using terminal, you can right-click on it, go to "Properties", and in the "Permissions" tab, check the box "Allow executing as program".
-