- 1 year ago
How to set an alias to open a file in Bash
To set an alias to open a file in Bash, you can add the alias to your Bash configuration file, such as ~/.bashrc
or ~/.bash_profile
. Here's an example of how to create an alias to open a file using the default application:
Open your Bash configuration file using a text editor:
bashnano ~/.bashrc
Add the following line at the end of the file to define the alias:
bashalias openfile='xdg-open'
In the above example,
openfile
is the alias name, andxdg-open
is the command to open the file using the default application.Save the file and exit the text editor.
To make the changes take effect, either restart your terminal or run the following command to reload the Bash configuration:
bashsource ~/.bashrc
Now, you can use the openfile
alias followed by the file name to open the file. For example:
bashopenfile myfile.txt
This will open the myfile.txt
file using the default application associated with the file type on your system.