Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to locate files in a directory that have strings (with no spaces) longer than x length?

share|improve this question
up vote 14 down vote accepted

I consider myself a regex noob, but I created a bunch of files with variable length strings in them and I think I got what you wanted, try this:

user@host$ grep -e '[^\ ]\{7,\}' *

For those who don't quite understand this:

-e makes grep search using a regex. [^\ ] means to match a single character except space. \{7,\} means to match a string of 7 or more characters. If you were to put another number afther , it would be strings between 7 and x characters.

share|improve this answer
worked great, thanks. – Susan Jan 31 '10 at 3:42
To use any 'space' as a break (space, tab etc), use a similar Perl regex: grep -P '[\S]{7,}' * – fukawi2 May 2 '13 at 23:44

I couldn't get the example above to work. I was searching for lines in a CSV file longer than 10000 characters. I messed around quite a bit and got this... Find lines longer than 9999 characters...

grep -a -e '[^\]\{9999,\}' *.csv >../keslerun.csv

And this is what I really needed. Lines in CSV file less than 10000 characters. find lines less than 9999 characters

grep -a -v -e '[^\]\{9999,\}' *.csv >../keslerrun.csv
share|improve this answer
Hopefully it completed in less than 12 parsecs? – maik May 3 '13 at 21:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.