The rest of the options give you more control over libtrash. These options are:
- TRASH_CAN = Trash
This entry sets the name for the subdirectory where deleted files will be stored. The default name for this directory is Trash. Any name may be used. To change the directory name, enter the new name without any slashes. - IN_CASE_OF_FAILURE =
This setting determines how libtrash reacts when there is a failure. Setting this value to PROTECT prevents files from being deleted by the standard Linux function. Setting the value to ALLOW_DESTRUCTION overrides libtrash. - SHOULD_WARN = YES
This setting enables a warning message for libtrash. It's normally a good idea to remind users that their files will be permanently deleted when libtrash is disabled. This is especially true if users on the system are new to Linux or for users who assume libtrash is always running. - PROTECT_TRASH = YES
This setting protects files in the trash from being deleted. Files placed in the user's trash represent a special case. Libtrash functions by sending deleted files to a trashcan in the user's home directory. When the user wants to delete files in the trashcan, the default libtrash doesn't work. - IGNORE_EXTENSIONS =
This setting allows you to specify files with specific extensions that may be deleted without being copied to the trashcan. To specify which types may be ignored by libtrash, create a semicolon-delimited separated list of the file extensions to be ignored. Do not include a dot (.) before the extension. For example, to allow .o, .c, and log files to be deleted without being moved to the trashcan, use this entry: IGNORE_EXTENSIONS = o; c; log - IGNORE_HIDDEN = YES
Hidden files and files inside hidden directories may be sent to the trash. Setting this entry to YES allows Linux to delete hidden files without moving them to the trash. Stick with the default value of YES and override it if you must on a per-user basis. - IGNORE_EDITOR_BACKUP = NO
This entry will ensure that backups of important files are always sent to the trash. These are files that end with a tilde (~). The default is YES. Changing this setting might be a good idea. - IGNORE_EDITOR_TEMPORARY = YES
This entry concerns temporary files created by editors. Setting this entry to YES allows these temporary files to be removed without moving them to the trash. Set the entry to NO to allow libtrash to move these files to the user's trash. Stick with the default and change this setting on a per-user basis. - LIBTRASH_CONFIG_FILE_UNREMOVEABLE = YES
This entry provides protection for the user's personal libtrash configuration file. Removing your own configuration file will cause unexpected actions from libtrash. Leave this setting alone. - TRASH_SYSTEM_ROOT
The TRASH_SYSTEM_ROOT variable specifies the location of the directory under the trash that will function as the root (/) of the file system whenever the GLOBAL_PROTECTION variable is set to YES. If global protection is not used, this variable is ignored. This variable always uses a directory name with no slashes. The default setting is TRASH_SYSTEM_ROOT = SYSTEM_ROOT. - UNREMOVEABLE_DIRS=/bin;/boot;/dev;/etc;/lib;/sbin;/usr
Any directory on the system can be marked as an unremoveable directory. All files in these directories are protected from deletion by any user running libtrash. This may be the most important step in the entire libtrash configuration process. By carefully establishing a list of protected directories, the administrator can prevent users from either accidentally or intentionally removing critical directories and files. The default list is a commented line in the /libtrash.conf file. To activate this list, remove the comment (#) from the beginning of the line. To add additional directories, add a semicolon to the end of the line, and then add the path to the directory you want protected. In the example, the directory /usr/local/users has been added to the default entry to protected programs. - UNCOVER_DIRS =
Any directories listed as unremoveable may be temporarily removed from the above list by adding the directory to the UNCOVER_DIRS list. The default list is empty. Leave it empty. Any files that need to be uncovered should be added to an UNCOVER_DIRS list in the user's personal configuration file. This prevents all users from being able to remove specified directories. - USER_TEMPORATY_DIRS = temp
The USER_TEMPORARY_DIRS entry specifies a directory or list of directories under the user's home directory where temporary files are created. Files in these directories are always permanently deleted. Leave this setting if you don't require this feature. - REMOVEABLE_MEDIA_NMOUNT_POINTS
This setting prevents copies of removeable media from being copied to the trashcan when global protection is used. The REMOVEABLE_MEDIA_NMOUNT_POINTS setting is activated by default. This setting is ignored when global protection is disabled. - EXCEPTIONS
The EXCEPTIONS setting is used to remove protection from files normally considered unremoveable. This allows essential actions by programs, such as creating or deleting a lock file or mounting/unmounting a drive, and may require some files in the UNREMOVEABLE_DIRS setting to be created and deleted. The default entry is EXCEPTIONS = /etc/mtab; /etc/resolv.conf; /etc/adjtime; /etc/upsstatus
Study these entries, and consider your system requirements. Once the configuration settings are entered, the next step is to compile and install libtrash.
Creating a personal configuration file
Personal configurations are created in each user's home directory. These settings are identical to the ones in the libtrash.conf file mentioned above, and, unless stated above, you should override the settings. For example, you could create the file ~/.libtrash in your home directory with these entries:
- GLOBAL_PROTECTION = NO
- IGNORE_EXTENSIONS = bat; exe;com
These entries disable global protection, and allow any files with the extension bat, exe, or com to be permanently deleted without moving them to the trash.
On multiuser systems, the administrator will probably want all users or groups of users to be able to use libtrash. On these systems, the root user should create a standard libtrash configuration for each group of users requiring a predefined configuration.
Installing libtrash
Libtrash requires ldconfig to compile properly. If the ldconfig executable is located in your /sbin/directory, Linux won't automatically find Idconfig during the compilation process. To correct this, run the cp /sbin/ldconfig /usr/bin/ldconfig command as root to copy ldconfig to the /usr/bin directory.
Libtrash is installed by running these two commands as root:
- make
- make install
Activating libtrash
Because libtrash is a shared library and not an executable program or script, there is no libtrash command to run. To activate the libraries associated with libtrash so that it is activated automatically when any user logs into the system, add this to the /etc/profile file:
export LD_PRELOAD=/usr/local/lib/libtrash.so.1.8
Next, add these two aliases to the /etc/profile file. These aliases allow easy activation and deactivation.
alias trashon="export TRASH_OFF=NO"
alias trashoff="export TRASH_OFF=YES"
After these aliases are created, libtrash can be activated or disabled with these commands:
trashon
trashoff
Testing the installation
To test your libtrash installation, simply create a file and delete. The file should then be moved into the Trash directory under your home directory. To run the test, use this series of commands:
touch trashtest
vi trashtest
rm trashtest
cd Trash
ls
When I first created the trashtest file using the touch command, I didn't add any text to the file. Accordingly, when I deleted the trashtest file, libtrash didn't move it to the Trash directory. To avoid making this mistake, simply add some text to the trashtest file to ensure libtrash moves it to the Trash directory.
Libtrash can save your files from your own mistakes
The libtrash library isn't limited to command line operations. Libtrash will work with graphical file managers, e-mail applications, and other applications in which files are deleted. All Linux users should have insurance against accidentally deleting files from the system, and libtrash does a good job of providing that insurance. If you want some protection against losing files, libtrash should be in your toolkit.
TechRepublic is the online community and
information resource for all IT professionals, from support staff to executives. We offer in-depth technical articles written for
IT professionals by IT professionals. In addition to articles on everything from Windows to e-mail to fire walls, we offer IT industry analysis,
downloads, management tips, discussion forums, and e-newsletters.
©2003 TechRepublic, Inc.
Do you need help with UNIX? 





Leave a comment