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.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay