TransWikia.com

Firefox temporary files

Unix & Linux Asked by Daniele on December 3, 2020

In Firefox, when I choose to open a file without saving it and without an internal plugin (like a pdf or a doc file) the default behavior is that the file is saved in /tmp as a temporary file and that the chosen application (like mupdf or libreoffice) is opened with the temporary file as input.
The filename of the temporary file is usually the original name of the downloaded file, unless a file with the same name is already present in /tmp. In such case, a suffix is appended to the filename (-1, -2, -3, etc) before its extension.
The temporary files are deleted from /tmp when Firefox is closed (unless the default behavior is changed).

I think it would be much more convenient to delete each temporary file when it is not needed anymore (i.e., when the application using it stops using it). Is there a way to implement this?

As an alternative, a better behavior for me would be to replace the existing file in /tmp with the new one in case a file with the same name already exists? (i.e., without changing the filename). Is this possible?

2 Answers

To delete the temporary file as soon as possible, you can write a wrapper, like:

#!/bin/sh
the-application "$1"
rm -f "$1"

replacing the-application by the name of the real executable, and ask Firefox to use this wrapper instead of the application. Or:

#!/bin/sh
the-application "$1"
case "$1" in
  /tmp/*) rm -f "$1" ;;
esac

This form is safer in case future Firefox versions do not create a new file for "file:" URL's (you don't want the file to be removed in this case).

Note that some applications return immediately and may fail to work correctly if the file is removed before the application is quit. In such a case, there isn't much you can do (at least in a reliable way).

Concerning the alternative (to replace an existing file with the same name), this can yield clashes with other applications that use /tmp, with possible security implications. This is not a good idea in general.

Correct answer by vinc17 on December 3, 2020

I've been sitting in Firefox parameters for some time and they really look ugly. But! In your example, there is a simple solution.

First, you must create your own script to include setting temporary path, then running browser, and finally removing files from temporary path. This would look like

#!/bin/bash
tmp_folder='/tmp/firefox-tmp'
export TMP=$tmp_folder
export TEMP=$tmp_folder  # (my Iceweasel needs setting both TMP and TEMP!)
mkdir $tmp_folder
firefox
rm -f $tmp_folder/*

Save this file somewhere (on desktop like: /home/<user>/Desktop/firefox.sh and grant execute permission with

chmod +x full_path_to_file_on_desktop

Right now, when you run script, you will redirect all temporary files as you needed to this /tmp/firefox-tmp folder, and once browser is closed, folder content is removed.

TIP: I haven't found any settings in Firefox (about:config) to change default behaviour as you faces, so please use my solution. It really works :)

You could also play with user profiles and cache profiles, but that's a topic for another...yyy...topic ;)

Answered by Alan Staney on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP