Command to Search for Filenames Exceeding 143 Characters?

So some background first: I am attempting to convert a non-encrypted shared folder into an encrypted one on my Synology NAS and am seeing this error:

Synology NAS Error

So I would like to locate the offending files so that I may rename them. I have come up with the following grep command: grep -rle '[^ ]{143,}' * but it outputs all files with paths greater than 143 characters:

#recycle/Music/TO SORT/music/H/Hooligans----Heroes of Hifi/Metalcore Promotions - Heroes of Hifi - 03 Sly Like a Megan Fox.mp3
...

What I would like is for grep to split on / and then perform its search. Any idea on an efficient command to go about this (directory easily contains hundreds of thousands of files)?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Although the GNU ‘findutils-default’ regular expression syntax doesn’t provide a {n,m} interval quantifier, you can use a -regex test in GNU find if you select a different regextype, for example:

find . -regextype posix-extended -regex '.*/[^/]{143,}$'

or

find . -regextype egrep -regex '.*/[^/]{143,}$'

or

find . -regextype posix-basic -regex '.*/[^/]{143,}$'

etc. There may be other regextypes that support {n,m} intervals, either with or without escaping.

Compared to piping the results of find to a separate grep command, this will match across newlines (i.e. the find regex flavors differ from their namesakes in that . matches the newline character by default).

Method 2

Try:

find /your/path | grep -E '[^/]{143,}$'

Method 3

If you’ve already got a locate db, it is very fast at this.

locate --regex '.*/[^/]{143,}$'


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x