- Published on
Seamless CSV Viewing on Linux with csvlens
- Authors

- Name
- Jeremy Garrell
If you're a Linux user who frequently works with CSV files, you've likely experienced a common frustration: the often-limited software options for quickly viewing and navigating large datasets. While Windows and macOS might boast feature-rich spreadsheet applications, Linux users often find themselves resorting to clunky editors or full-blown office suites for a simple peek at a CSV. This can be slow, resource-intensive, and frankly, overkill for a quick look.
This is where csvlens shines – a fantastic command-line interface (CLI) tool that brings powerful CSV viewing capabilities right into your terminal, filling a crucial gap in the Linux software ecosystem. If you've already installed csvlens via cargo install, you're just a few steps away from making it your default CSV viewer. This post will guide you through setting up your Ubuntu system to automatically open CSV files with csvlens when you click them, providing a much-needed, seamless terminal-based solution.
Step 1: Find Your csvlens Executable
First things first, we need to locate the csvlens executable. Since you installed it with cargo install, it's most likely in your Cargo bin directory, usually ~/.cargo/bin/. To confirm the exact path, open your terminal and run:
which csvlens
You'll get an output similar to /home/yourusername/.cargo/bin/csvlens. Make sure to note this full path down, as you'll need it in the next step.
Step 2: Create a Desktop Entry for csvlens
To tell your graphical environment how to launch csvlens, we'll create a .desktop file. This file acts as a shortcut and contains instructions for opening your application.
Open a text editor and create a new file named csvlens.desktop in the ~/.local/share/applications/ directory:
nano ~/.local/share/applications/csvlens.desktop
Now, paste the following content into the file. Crucially, replace /home/yourusername/.cargo/bin/csvlens with the actual path you found in Step 1.
[Desktop Entry]
Name=CSVLens Viewer
Comment=View CSV files with csvlens in a terminal
Exec=gnome-terminal -- /bin/bash -c "/home/yourusername/.cargo/bin/csvlens %f; echo 'Press Enter to close'; read"
Icon=text-x-generic
Terminal=false
Type=Application
MimeType=text/csv;
Categories=Utility;TextEditor;
Let's break down that important Exec line:
Exec=: This tells the system what command to run.gnome-terminal --: This part specifies that the command should open in a newgnome-terminalwindow. If you use a different terminal (likekonsole,xfce4-terminal, etc.), replacegnome-terminalwith your preferred terminal's command./bin/bash -c "...": This executes a Bash command within the terminal.**YOUR_CSVLENS_PATH** %f: This is where your actualcsvlenspath goes.%fis a placeholder that your file manager automatically replaces with the full path of the CSV file you clicked.; echo 'Press Enter to close'; read": This is a neat trick! Becausecsvlensis a terminal application, the terminal would normally close immediately aftercsvlensfinishes. This addition prints "Press Enter to close" and then waits for you to press a key, keeping the terminal open until you're ready.
Step 3: Set csvlens as the Default for CSVs
Now, let's make sure your system knows to use csvlens.desktop for CSV files. We'll use the xdg-mime command for this.
First, you can check what's currently set as the default for CSVs:
xdg-mime query default text/csv
Then, set your newly created csvlens.desktop as the default:
xdg-mime default csvlens.desktop text/csv
Step 4: Update Your MIME Database (Good Practice)
It's a good idea to refresh your system's MIME type database to ensure the changes are picked up:
update-desktop-database ~/.local/share/applications/
Step 5: Test It Out!
You're all set! Navigate to a .csv file in your file manager and double-click it. A new terminal window should pop open, displaying your CSV file beautifully with csvlens. Once you're done viewing, simply press Enter (or any key) to close the terminal.
Troubleshooting Tips
- Terminal opens and closes immediately: Double-check the
Execline in yourcsvlens.desktopfile, especially theecho 'Press Enter to close'; readpart. A small typo can cause this. csvlensdoesn't open:- Verify the
Execpath incsvlens.desktopprecisely matches the output ofwhich csvlens. - Confirm that
csvlensruns correctly when you typecsvlens your_file.csvdirectly in your terminal. - Ensure there are no typos in the
MimeTypeline (MimeType=text/csv;).
- Verify the
- Want to revert? You can right-click a CSV file, choose "Open With Other Application," and select your previous default. Alternatively, you can use
xdg-mimeagain to set a different default:xdg-mime default libreoffice-calc.desktop text/csv # or your preferred spreadsheet app
Enjoy your new, streamlined CSV viewing experience directly from your terminal, finally giving you a robust and efficient solution for CSVs on Linux!