Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

find command question

Posted on 2006-04-21
4
Medium Priority
?
178 Views
Last Modified: 2013-12-16
I'm trying to do something like this, is there a way?

find . ! -name ( \*.config -a \*.info )

I want to find all files which don't have the name *.config or *.info.  Can you tell me how to use the "-a" flag to accomplish this?
0
Comment
Question by:bryanlloydharris
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
ravenpl earned 1000 total points
ID: 16513791
find . \! -name \*.config -a \! -name \*.info
0
 
LVL 22

Assisted Solution

by:pjedmond
pjedmond earned 1000 total points
ID: 16514333
As always there are many ways to do the same thing. I rather prefer this approach:

find .

lists all the files under . , but we only want files that do not end in *.config or *.info.

The grep for *.info is:

grep "\.info$"

\ escapes the period(.) so that it cannot represent any char, and $ anchors the the match to the end of the line so that names such as abc.info.bu or abc.info2 etc are not matched.

We need to invert this (grep -v) giving:

grep -v "\.info$"

which matches anything *NOT* ending in .info

Finally repeat the process for *.config, and pipe(|) the requirements together:

find . | grep -v "\.info$" | grep -v "\.config$"

et voila!! you have all files not ending in .info or .config

Obviously, this approach is extremely versatile for other search requirements!

HTH:)
0
 
LVL 3

Author Comment

by:bryanlloydharris
ID: 16523933
I see both are great.  I have been using the one from raven for a long time but I am curious if there is a way to save typing from it.

The reason I can't use the grep is because I need to do -exec in the find command.  But I supposed I could then use xargs as well and save some typing.

Thanks both.
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16524446
I see both are great.  I have been using the one from raven for a long time but I am curious if there is a way to save typing from it.

>>Look up alias!

The reason I can't use the grep is because I need to do -exec in the find command.  But I supposed I could then use xargs as well and save some typing.

>>And....of course you can use grep:) See my approach to this example:

http://www.experts-exchange.com/Operating_Systems/Linux/Q_21816739.html

:)

Thanks both.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question