this post was submitted on 30 Jun 2023
20 points (95.5% liked)

Linux

48152 readers
752 users here now

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

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Hi,

I'm looking for a package that will allow me to configure some rules for moving folders and then watch a folder and automatically move folders or files that match rules to a certain other directory. Does something like this exist?

The use case is that I have data being saved to a single directory by other devices, and then I would like to reorganize it based on the file or folder name.

Or anyone have any other ideas of how to do this?

you are viewing a single comment's thread
view the rest of the comments
[–] Sulinstajn@lemmy.ml 3 points 1 year ago* (last edited 1 year ago)

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.