How To
Summary
Techniques for clearing out old files from the system temporary directory, /tmp.
Steps
The temporary directory, /tmp, is used in the same way it is on Linux and Unix systems. Programs that create temporary files or directories create them in this path. The major difference between IBM i and Linux or Unix is that IBM i does not clear this directory when the operating system restarts like Linux and Unix do. Over time, a system can accumulate many 'garbage' links in the temporary directory.
The easiest way to resolve this problem in a manner similar to Linux and Unix is to clear the directory when the system restarts. To accomplish this goal, you can add the following command to the beginning of your startup program:
QSH CMD('clrtmp')
It can be difficult to determine whether a link in the temporary directory is still needed unless you know what process created it. If the link is older than the date of your last system restart, then it is safe to delete. For any newer links, the ability to delete it without any repercussions depends on the process or processes that make use of the link. It requires system analysis of those processes to determine the relative safety of such a deletion; that is beyond the scope of what IBM can address with you.
The following script can be run in the IBM i Access Client Solutions "Run SQL Scripts" tool to clean up any links that are older than the last system restart:
--
-- Script to delete items from /tmp that from processes prior to the last IPL.
-- Create a global variable to hold the number of days since the last system restart
CREATE OR REPLACE VARIABLE QGPL.DAYSSINCEIPL INT;
-- Set the value for the global variable
SET QGPL.DAYSSINCEIPL=(
SELECT DAYS(CURRENT_DATE) - DAYS((SELECT DATE(job_entered_system_time)
FROM TABLE (
qsys2.job_info(job_status_filter => '*ACTIVE', job_user_filter => 'QSYS')
) x
WHERE job_name = '000000/QSYS/SCPF'))
FROM SYSIBM.SYSDUMMY1);
-- Use QShell functionality with the variable to delete any files with a last modified prior to the last system restart
BEGIN
DECLARE @CMD VARCHAR(200);
SET @CMD = 'QSH CMD(''find /tmp/*.* -mtime +' || (QGPL.DAYSSINCEIPL + 1) || ' -exec rm -d {} \;'')';
CALL QSYS2.QCMDEXC (@CMD);
END Related Information
Document Location
Worldwide
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CGvAAM","label":"Integrated File System"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Was this topic helpful?
Document Information
Modified date:
07 June 2025
UID
ibm17032435