Efficiently Deleting Large Amounts of Temporary Files
The /tmp directory can quickly become overloaded with temporary files, such as PHP session files (sess_*). This can degrade system performance and complicate file system management.
Recommended solution
To delete large volumes of these files efficiently, run the following command:
find /tmp -name "sess_*" -type f -print0 | xargs -0rn 20 rm -f
How the command works
find /tmp -name "sess_*" -type f -print0: searches the/tmpdirectory for files beginning withsess_. The-print0flag uses null character separation to safely handle filenames with spaces or special characters.xargs -0rn 20 rm -f: reads the null-separated input (-0), processes files in batches of 20 (-n 20), and runsrm -fto force deletion without prompts.
This method is more stable and faster than using a wildcard rm sess_* in heavily populated directories.
Warning
Always double-check the pattern sess_* to avoid accidentally deleting unintended files.