Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find files that are too long for Synology encrypted shares

When trying to encrypt the homes share after the DSM6.1 update, I got a message that there are files with filenames longer than 143 characters. This is the maximum length for a filename in an encrypted Synology share.

Because there is a lot of stuff in the homes share (mostly my own) it was not practical to search for the files by hand. Nevertheless these files had to be deleted or renamed to allow the encryption of the share.

I needed an automated way to find all files in all subdirectories with a filename longer than 143 characters. Searching for the files via the network share using a Windows tool would probably have taken way too long.

I have figured out the solution by myself (with some internet research though, because I'm still a n00b) and want to share it with you, so that someone with the same problem might benefit from this.

like image 590
Marlon Avatar asked Mar 09 '23 13:03

Marlon


1 Answers

So here it goes:

The find function in combination with grep does the trick.

find /volume1/homes/ -maxdepth 15 | grep -P '\/[^\/]{143,}[^\/]'

For my case I assumed that I probably don't have more than 15 nested directories. The maximum depth and the starting directory can be adjusted to your needs.

For the -P argument you might need to have Perl installed, I'm not sure about that, though.

The RegEx matches all elements that have a / somewhere followed by 143 or more of any character other than / and not having a / afterwards. By this we only get files and no directories. For including directories you can leave out the last condition

The RegEx explained for people who might not be too familiar with this:

  • \/ looks for a forward slash. A new file/directory name begins here.
  • [^\/] means: Every character except /
  • {143,} means: 143 or more occurrences of the preceding token
  • [^\/] same as above. This excludes all results that don't belong to a file.
like image 157
Marlon Avatar answered Apr 02 '23 10:04

Marlon