free space


How to Free Space from /var/log by Removing Old Log Files

Introduction

Managing disk space is a critical task for system administrators and users alike. In Linux systems, the /var/log directory can become a source of space consumption due to the accumulation of log files. In this post, we’ll explore a simple command to free up space by deleting old compressed log files and discuss its pros and cons.

The Command

The command find /var/log -type f -name "*.gz" -delete is a powerful way to clean up space in the /var/log directory. Here’s a breakdown of what this command does:

  • find /var/log: Searches in the /var/log directory.
  • -type f: Restricts the search to files.
  • -name "*.gz": Looks for files ending with .gz, which are typically compressed log files.
  • -delete: Deletes the files that match the search criteria.

Pros

  1. Efficient Space Management: This command quickly frees up disk space consumed by old, compressed log files, which is essential for the smooth functioning of the system.
  2. Automatable: The command can be automated through a cron job or a script, making regular maintenance easier.
  3. Selective Deletion: It specifically targets .gz files, which are usually older log files that have been compressed, thus keeping the most recent logs intact.

Cons

  1. Potential Data Loss: Important historical data in the log files could be lost if they are deleted without proper review.
  2. Lack of Control Over File Age: This command does not discriminate based on the age of the log files. It deletes all .gz files, regardless of how recently they were compressed.
  3. No Backup: The command executes a direct deletion without creating backups, which could be problematic if a file is deleted accidentally.

Best Practices

  • Review Files Before Deletion: Run the command without the -delete flag first to review which files will be deleted.
  • Implement Log Rotation: Set up log rotation to manage log files systematically, compressing and archiving older logs while deleting the oldest ones.
  • Backup Important Logs: Always keep a backup of important logs before running any deletion command.

Conclusion

While the command find /var/log -type f -name "*.gz" -delete is an effective way to free up space in the /var/log directory, it’s important to use it judiciously. Understanding its pros and cons helps in making informed decisions about log management in a Linux environment.


How to empty the gnome tracker3 cache?

To empty the cache of gnome tracker3, you can follow the steps below:

Open a terminal window by pressing Ctrl + Alt + T.

Type the following command to stop the tracker daemon:

tracker3 daemon -t;

Type the following command to clear the tracker database:

tracker reset --filesystem;

This command will remove all indexed data from the tracker and clear its cache. (Remove filesystem indexer database)

Restart the tracker daemon by typing the following command:

tracker daemon -s ;

This will start the tracker daemon again, and it will begin to rebuild its database and cache.

After following these steps, the cache of gnome tracker3 will be emptied.

Execution example:

$ tracker3 daemon -t
Found 1 PID…
  Killed process 13705 — “tracker-miner-fs-3”
$ tracker3 reset --filesystem
Found 1 PID…
  Killed process 13705 — “tracker-miner-fs-3”
$ tracker3 daemon -s
Starting miners…
  ✓ File System

Remove Disabled Snaps.

LANG=C snap list --all | awk '/disabled/{print $1" --revision "$3}' | xargs -rn3 sudo snap remove;

Let us break down the command for you:

  1. LANG=C sets the language to English (C locale), which can be helpful to ensure consistent behavior across different systems with different default languages. We used this to make sure that the word disabled will appear for disabled snaps and not some other translation.
  2. snap list --all lists all installed snaps (i.e., packages) along with their details. The output of this command is piped to the following command.
  3. awk '/disabled/{print $1" --revision "$3}' searches for lines in the output that contain the word “disabled” and prints the first field (i.e., the name of the snap) followed by the string “–revision” and the third field (i.e., the revision number). This output is piped to the next command.
  4. xargs -rn3 sudo snap remove takes groups of three arguments from the input and runs the command snap remove with those arguments. In this case, the first argument is the name of the disabled snap; the second argument is the string “–revision”, and the third argument is the revision number. This will remove all disabled snaps and their associated revisions.

So, in summary, the command searches for all disabled snaps on the system, extracts their name and revision number and then removes them using the snap remove command. This is a very useful command to free up some space without losing data or functionality.