DEV Community

Jakariya Abbas
Jakariya Abbas

Posted on

1 1 1 1 1

How to Open Windows .url Files in Arch Linux Using a Bash Script

Windows .url files store web shortcuts. If you have .url files and want to open them in Linux, follow this tutorial to create a Bash script that does it automatically.

Step 1: Create the Script File

First, open a terminal and create a new script file:

nano open-url
Enter fullscreen mode Exit fullscreen mode

This command opens the Nano text editor so you can write the script.


Step 2: Write the Bash Script

Copy and paste the following code into Nano:

#!/bin/bash

# Check if a file is provided
if [[ -z "$1" ]]; then
    echo "Usage: $0 <file.url>"
    exit 1
fi

# Check if the file exists
if [[ ! -f "$1" ]]; then
    echo "Error: File '$1' not found!"
    exit 1
fi

# Extract URL from the .url file
url=$(grep '^URL=' "$1" | cut -d'=' -f2)

# Check if URL was found
if [[ -z "$url" ]]; then
    echo "Error: No URL found in '$1'"
    exit 1
fi

# Open the URL in the default browser
xdg-open "$url"
Enter fullscreen mode Exit fullscreen mode

After pasting the script, save the file by pressing:

CTRL + XYEnter


Step 3: Make the Script Executable

Now, run this command to give the script permission to execute:

chmod +x open-url
Enter fullscreen mode Exit fullscreen mode

Step 4: Make It a System Command

To use this script from anywhere in the terminal, move it to /usr/local/bin:

sudo mv open-url /usr/local/bin/open-url
Enter fullscreen mode Exit fullscreen mode

Now, you can open any .url file like this:

open-url myshortcut.url
Enter fullscreen mode Exit fullscreen mode

Protip: You can set this as a default application/command to open .url files when clicked.

Conclusion

With this simple script, you can easily open Windows .url files in Arch Linux. It checks if the file exists, extracts the URL, and opens it in your default browser using xdg-open.

Top comments (0)

👋 Kindness is contagious

If you found this post helpful, please leave a ❤️ or a friendly comment below!

Okay