Log File Maintenance and Cleanup
Log files sometimes take up a lot of disk space. Some applications have internal processes that run periodically to manage them and some do not. Often, this becomes a problems after a while as the logs consume all of your partition space.
You can manage these files yourself with a simple script running in a cronjob (or systemd timers if you’re so inclined) if they have a common naming convention and you have the proper access.
Let’s say you have an application called myapp that keeps
it’s logs in a directory called /opt/myapp/logs
and those
files all end with a .log
file extension.
cat >logmanage.sh <<"EOF"
#!/bin/sh
LOGDIR="/opt/myapp/logs"
# Compress all of the files older than a day
find ${LOGDIR} -name '*.log' -mtime +0 -exec compress {} \;
# Purge all of the logs older than a week
find ${LOGDIR} -name '*.Z' -mtime +7 -exec rm -f {} \;
EOF
These two commands will compress those files that are more than older than a day and remove the compressed files after a week.
Add a crontab entry to run this everyday and you’re all set.
Tags: cli, sysadmin, logs, find, motd
How to Clean Up the Fedora Root Folder
OK, so you’re running Fedora and you’re getting warnings that you’re running out of disk space on the root folder. What are your options?
The first thing to consider is resizing the root partition size. For that you can find instructions here
If that is not an option, then the next thing you probably should do
is find out which folders/directories are causing the issue. You can use
the du
command and some piping to figure this out:
Search the largest folders
$ sudo du --exclude="/home" -x -h -a / | sort -r -h | head -30
Common cleanable folders
Sometimes the issue is found in the docker cache:
$ docker system prune -a
or previous kernel versions:
$ sudo dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
Journal logs
$ sudo journalctl --vacuum-size=100M
Caches
The dnf package cache can be cleaned up too:
$ sudo dnf clean packages
You can also try cleaning up the Fedora version cache:
$ sudo dnf system-upgrade clean
Tags: cli, fedora, disk-space, clean, resize, sysadmin, motd
How to Change the UID or GID for a User or Group
Let’s assume we have a user, Jane Doe, with the username of jdoe and the UID of 1001 who we need to move to another UID (for some reason or another).
First, change the UID of the user:
# usermod -u 3001 jdoe
Next, use search and change all file’s ownership owned by this user:
# find / -user 1001 -exec chown -h jdoe {} \;
What if we need to change the GID of a group? Basically the same process can be used. Let’s say we want to change the admins group’s GID from 2001 to 4001.
First, change the GID:
# groupmod -g 4001 admins
Now, use search and change all file’s ownership owned by this group:
# find / -group 2001 -exec chgrp -h admins {} \;
Tags: cli, sysadmin, uid, gid, motd
How to Enable the Administrator Account in Windows
To activate the Administrator account on Windows, open the Command Prompt as Administrator from the Start Menu, or you can right-click on the "Start" menu and select the "Powershell" menu item, then enter:
net user administrator /active: yes
into the window. You should disable the account again when you're done.