inotifywait or watchexec can both watch a directory for changes then execute anything you want.
Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
inotifywait or watchexec
Excellent suggestion.
You can use find utility for that. I'm not at Linux machine right now, so maybe I can make mistake in commands, but something like this should work:
find /path/to/data/folder -name "type1name" -exec mv -t /path/to/dest/folder {} +
In this example, command find every file containing "type1name" in its name in folder /path/to/data/folder and move it into /path/to/dest/folder.
So if you have folder "~/data/all_data" containing files like "temperature_2023-06-30.csv", " temperature_2023-06-29.csv", "power_2023-06-30.csv" and "power_2023-06-29.csv", do:
mkdir ~/data/temperature
mkdir ~/data/power
find ~/data/all_data -name "temperature*" -exec mv -t ~/data/temperature {} +
find ~/data/all_data -name "power*" -exec mv -t ~/data/ {} +
More, you can tweak it into for examplee filtering according to current date and run that script every day.
Best I can think of would be a shell script combined with Cron.
But I'd love see alternatives. Ideal with a gui imo
I guess that there should be some tool exactly for that but I couldn't find it quickly
- You might want to take a look at filebeat, maybe that will fit your use-case. I take the part "automatically move folders or files that match rules to a certain other directory" verbatim and think it's not. Filebeat is rather to ingest logs and stream these elsewhere
- you could configure rules for your files in logrotate but it can only be executed hourly
- or just write a bash function/script that does the move/decides where to move the file to (executing logrotate should work too) and use one of these:
systemd-path is the cleanest and most portable solution. You define a path service to watch your directory for changes and trigger another service to perform certain actions then. It uses inotify.
https://man.archlinux.org/man/systemd.path.5.en
Here is a full example from our currently so beloved redhat: https://www.redhat.com/sysadmin/introduction-path-units
If you don't find the application you're looking for maybe you can write a bash script that runs on a Cron job. It's possible if you're just talking about file/folder names