The Two-Step Bottleneck
When cleaning up a massive Ubuntu Linux server, the standard workflow is incredibly slow: you run a find command to locate thousands of old log files, output that list to a text file, and then write a secondary script to read that list and execute the rm command. Not only is this tedious, but if a filename contains a strange special character or a space, the standard rm script will break. To achieve maximum efficiency, you must combine the search and the destruction into a single, highly optimized kernel operation.
Using the find Command with -delete
The Linux find command features a built-in -delete flag that instantly destroys any file the moment it matches your search criteria, bypassing the need for secondary scripts entirely.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To scan the
/var/log/directory for files ending in.gz(old compressed logs) and instantly delete them, type the following command exactly: sudo find /var/log/ -name "*.gz" -type f -delete- Press Enter and provide your administrator password.
Warning: Absolute Destruction
Use extreme caution. The -delete flag operates silently and permanently. There is no confirmation prompt, and the files do not go to a recycle bin. If you accidentally type a space in the wrong place, you could instantly delete thousands of critical system files. It is highly recommended to run the command without the -delete flag first to verify exactly what files will be targeted, and then simply press the “Up” arrow on your keyboard and append -delete to the end of the command once you are absolutely sure.