0

I have a mounted a folder to a seedbox. and in the folder i use syncthing. so it creates a " .stfolder" which is used for syncthing . basically i am having trouble finding a script to run that says look in x folder and xx subfolders but ignore hidden folder and delete everything that is older than xxx hours.

I tried to modify " find /path/to/files* -mtime +5 -exec rm {} ; " but had no success it kept finding the hidden folder

folder structure is like this
downloads/Movies/.stfolder and downloads/TV/.stfolder with TV and Movies having files and subfolders

Ultimately i am running this on a raspberry pi4. and my intent is to use a cron job to call a script to run every 12 hours or so . i have my seed box mounted to my rasperrypi 4 using curlftpfs

Any solution that works would be appreciated. Thank you

1
  • Note that "raspberry pi4" only identifies the hardware. What operating system is running on that machine would be a more useful information. Commented Mar 27, 2022 at 19:08

1 Answer 1

0
LC_ALL=C find /path/to/files/ -name '.*' -prune -o \
  -mtime +5 -type f -exec rm -f {} +

Would delete the regular files in and below the /path/to/files directory that have not been modified in the last 6 (not 5) days ignoring hidden ones (including the ones in hidden directories that are pruned from the directory tree find descends in).

If it's just the .stfolder directories you want to skip, you can do:

find /path/to/files/ -name .stfolder -type d -prune -o \
  -mtime +5 -type f -exec rm -f {} +

(in that case the LC_ALL=C is not necessary as that's only to work around the fact that * doesn't match across non-characters in some find implementations).

With zsh, you can just do:

rm -f /path/to/files/**/*(.m+5)

As hidden dirs / files are skipped by default.

Or for all old files except those in or below .stfolder directories:

set -o extendedglob # best in ~/.zshrc
rm -f /path/to/files/(^.stfolder/)#*(D.m+5)

(where D disables the skipping of hidden files / directories, and (^.stfolder)# matches any number of subdirectories other than those called .stfolder).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.