Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have: a directory with many nested subdirectories and files.

I would like: a list of all files whose name doesn't contain a certain string.

Example file structure:

foo/
foo/bar/foobar.txt
foo/foo/foobartest.txt
foo/foobartest.txt

If I enter my query with the string "test" it should return only /foo/bar/foobar.txt

I suppose one would use find with some regex?

Thanks a lot for your help!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Depends on what you want in the output.

ls -R | grep -v test

Or

find foo -type f | grep -v test

You can format the output with tools such as perl or awk

share|improve this answer
    
Thanks, that perfectly does the job! –  user2033157 Feb 1 '13 at 16:54

If you want to get

a list of all files whose name doesn't contain a certain string

you have to go with something like this:

find foo/ -type f -exec bash -c "basename {} | grep -v 'test' > /dev/null && echo {}" \; This will match only by filename, but output a relative path as find would normally do.
May be someone can propose a more elegant solution?

If matching against relative path is okay you can go with the answer, provided by @bodhi.zazen:

find foo -type f | grep -v test

share|improve this answer
    
Thanks for this option, too, but for my purposes @bodhi.zazen has provided a sufficient solution. –  user2033157 Feb 1 '13 at 16:58

Your Answer

 
discard

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.