Deleting files in Linux usually pushes you to the point of no return, with no hope of retrieving any files you may have accidentally deleted. But there is a way to get deleted files back, thanks to the freeware utility libtrash.
Every user, from the most casual user to the most experienced system administrator, has deleted files accidentally. If a Windows user makes such a mistake, most often the files can be recovered from the Recycle Bin. Of course, no self-respecting Linux user would be caught dead using Windows. But just because you're using Linux, you don't have to worry about permanently losing data—if you use the freeware utility libtrash.
What is libtrash?
Libtrash is more than a simple utility. It's a shared library that overrides the default actions Linux uses to delete files. Once libtrash is installed, deleted files will be moved into a subdirectory of the user's home directory named Trash. Libtrash allows users to use the normal Linux commands for deleting files, and libtrash will work with any files on the system.
Obtaining libtrash
You can obtain the latest version of libtrash directly from the author's Web site. The file is only 70 KB in size, so it will download quickly.
Unpack the libtrash archive by going to a command line and typing tar -zxvf libtrash-latest.tgz. When the libtrash archive is unpacked, you'll find the libtrash-1.8 directory in the current directory.
Configuring libtrash
Oddly enough, before you install libtrash, you must configure it. The libtrash-1.8/libtrash.conf file comes preconfigured with default settings. When libtrash is compiled, the /etc/libtrash.conf file is created, but this file only reflects the default configuration of libtrash.
That doesn't mean you can't reconfigure libtrash. It just takes a little extra work. There are two configurations available when libtrash is activated:
- Systemwide configuration: This is used for all users. This configuration is read from the /etc/libtrash.conf file.
- Personal configurations: Each user may use a separate configuration. Separate configurations are enabled through settings read from the .libtrash file in the home directory of each user.
Systemwide configuration
Systemwide settings are made through the /etc/libtrash.conf file. The required settings must be made prior to compiling libtrash. Changing the /etc/libtrash.conf file after compiling libtrash will not change the default behaviour of the program. To enforce the idea that this file should never be edited, no users are given write permission to this file. The /etc/libtrash.conf file is a read-only file for all users, including root. Therefore, you'll make changes to the libtrash-1.8/libtrash.conf file prior to installation.
There are four entries in the libtrash.conf that are used as environmental variables and cannot be changed by a user's personal configuration settings when libtrash is run. These four settings are:
- DEBUG
- PERSONAL_CONF_FILE
- WARNING_STRING
- UNCOVER_DIRS
The next four settings allow libtrash to intercept the standard routines Linux uses when files are unlinked or renamed. Your safest bet is to use the defaults for all of these settings:
- INTERCEPT_UNLINK= YES
- INTERCEPT_RENAME = YES
- INTERCEPT_FOPEN
- INTERCEPT_OPEN
Do you need help with UNIX? Gain advice from Builder AU forums








Leave a comment