How to get files without certain strings in their files names (reverse of *string*) on Linux?

To get files with certain string in their file names, it is quite straightforward:

ls *string*

However, how to do the reverse one: how to get files without certain strings in their files names on Linux?

You can get a list of file names by a combination of find and xargs as follows:

find . ! -name '.' -and ! -name '*string*' | xargs

or by ls and grep as follows:

ls | grep -v string | xargs

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *